Hi @intolap
Hope you are doing fine.
I performed a test on my lab site using the same code. A critical error was displayed on my end as well and found this in the logs:
PHP Parse error: syntax error, unexpected token "public", expecting end of file in /var/web/site/public_html/wp-content/mu-plugins/mu-plugin-test.php on line 4
Basically, it means the “public” keyword should not be used in the code, since the function is not added inside a class. You can modify the code and change it to this (removed the “public” word from the code):
<?php
add_action( 'forminator_custom_form_submit_before_set_fields', 'woow_forminator_beofre_set_handler');
function woow_forminator_beofre_set_handler( $entry, $form_id, $form_data_array ){
wp_mail( '[email protected]', 'test forminator - '.$form_id, json_encode($form_data_array).json_encode($entry) );
}
Hope this information helps.
Kind regards
Luis
Hi Luis,
You picked it right about the public keyword. Well, actually I am using this function inside a class. But just to post it here I extracted the code and forgot to remove the public keyword.
Did you check my lines of code without public keyword?
Thanks, now it works. I found the solution in the log.
add_action( ‘forminator_custom_form_submit_before_set_fields’, ‘woow_forminator_beofre_set_handler’, 10, 3);
What was missing is the priority and the number of arguments.
Does forminator have any option to add custom settings fields to every form programmatically?
Hi @intolap
Forminator does have option to add fields to forms via code, see here, please:
https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/#method-add_form_field
However, the “add_form_field” method is for adding actual field. I’m not quite sure what do you mean by “custom settings fields” specifically so I’m not sure if it will be suitable in this case.
Would you mind explaining a bit more what do you mean exactly by “custom settings field”?
Kind regards,
Adam
Hi @intolap
I hope you are doing well and safe!
We haven’t heard from you in a while, I’ll mark this thread as resolved.
Feel free to let us know if you have any additional questions or problems.
Best Regards
Patrick Freitas