Conditional FormIt hooks

I don’t think this is possible.

The code runs all the hooks in this foreach loop

There is no way to change the $hooks array from the outside and the only way to break the loop is to return false in the hook (which makes the form submission unsuccessful).


This should theoretically be possible, but you have to test it.

The built-in “email” hook is the class Sterc\FormIt\Hook\Email (= $className).
The “email” hook is executed like this in the code:

$this refers to the variable $hook in a custom hook snippet.
The $fields variable should also be available in the custom hook snippet.

So code like this might work:

...
// run the "email" hook in a custom hook snippet
$class = new Sterc\FormIt\Hook\Email($hook, $hook->config);
$success = $class->process($fields);
...