Conditional FormIt hooks

If I have my hooks variable in formit setup like this:

hook1, hook2, hook3, email

Is it possible to put some code at the end of hook3, where if a condition occurs, it skips the email hook but still returns a successful form?

Thanks.

OR…

Can I run a hook inside another hook? This will solve my problem. One condition inside hook3 can either run the email hook, or not.

Then I’d take off the email hook at the end of the FormIt snippet.

You could take the code from the email hook into the hook3 and send the mails inside that hook conditionally.

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);
...

Thanks a lot for the responses. I’ll try to see the most efficient way of sorting this out.