• Resolved javmah

    (@javmah)


    when using “forminator_custom_form_submit_field_data” hook below error show in the log. is there any solution for this?

    [09-Aug-2023 10:41:24 UTC] PHP Warning: Invalid argument supplied for foreach() in C:\wamp64\www\office\wp-content\plugins\forminator\library\modules\custom-forms\front\front-action.php on line 1211
    [09-Aug-2023 10:41:24 UTC] PHP Stack trace:
    [09-Aug-2023 10:41:24 UTC] PHP 1. {main}() C:\wamp64\www\office\wp-admin\admin-ajax.php:0
    [09-Aug-2023 10:41:24 UTC] PHP 2. do_action($hook_name = ‘wp_ajax_forminator_submit_form_custom-forms’) C:\wamp64\www\office\wp-admin\admin-ajax.php:188
    [09-Aug-2023 10:41:24 UTC] PHP 3. WP_Hook->do_action($args = [0 => ”]) C:\wamp64\www\office\wp-includes\plugin.php:517
    [09-Aug-2023 10:41:24 UTC] PHP 4. WP_Hook->apply_filters($value = ”, $args = [0 => ”]) C:\wamp64\www\office\wp-includes\class-wp-hook.php:334
    [09-Aug-2023 10:41:24 UTC] PHP 5. Forminator_Front_Action->save_entry(”) C:\wamp64\www\office\wp-includes\class-wp-hook.php:310
    [09-Aug-2023 10:41:24 UTC] PHP 6. Forminator_CForm_Front_Action->handle_form($preview = uninitialized) C:\wamp64\www\office\wp-content\plugins\forminator\library\abstracts\abstract-class-front-action.php:450
    [09-Aug-2023 10:41:24 UTC] PHP 7. Forminator_CForm_Front_Action::maybe_create_post() C:\wamp64\www\office\wp-content\plugins\forminator\library\modules\custom-forms\front\front-action.php:950
    [09-Aug-2023 10:41:24 UTC] PHP 8. Forminator_CForm_Front_Action::get_post_data_fields() C:\wamp64\www\office\wp-content\plugins\forminator\library\modules\custom-forms\front\front-action.php:1093
    [09-Aug-2023 10:41:24 UTC] PHP 9. Forminator_CForm_Front_Action::get_specific_field_data($type = ‘postdata’) C:\wamp64\www\office\wp-content\plugins\forminator\library\modules\custom-forms\front\front-action.php:1060
    [09-Aug-2023 10:41:24 UTC] PHP Warning: Invalid argument supplied for foreach() in C:\wamp64\www\office\wp-content\plugins\forminator\library\modules\custom-forms\front\front-action.php on line 1431
    [09-Aug-2023 10:41:24 UTC] PHP Stack trace:

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @javmah,

    I hope you are doing well today!

    The error you’re seeing is generally caused when a foreach loop is expecting to cycle through an array or object, but instead receives something else, like a string or integer. In your case, it seems that the forminator_custom_form_submit_field_data hook is where the error originates.

    Possible solutions:
    1- Check that forminator_custom_form_submit_field_data hook is correctly returning an array or object. You can test this by using a debugging tool, or by printing/logging the output of the hook.
    Ensure there is defensive coding in the instance where the foreach loop is being utilized. That means, include checks to validate that the input is indeed an array or object before attempting to use foreach.

    2- Examine the input or data source for your forminator_custom_form_submit_field_data hook. If that hook often deals with arrays or objects, but is sometimes passed another data type instead, then it could be causing your errors.

    3- If you have included custom hooks or filters with forminator_custom_form_submit_field_data in your plugins or themes, ensure that the returned data is an array or object. It’s quite possible that the output is being inadvertently overwritten here.

    4- Lastly, check for conflicts with other plugins or your theme. If you’re working in a test environment, you could try disabling some other plugins or switching to a simple theme to see if the issue still persists. It might not be the forminator_custom_form_submit_field_data hook at all, but a different function interfering with your expected output.

    Kind regards,
    Zafer

    Thread Starter javmah

    (@javmah)

    Dear Zafer, thanks for your reply. I didn’t write anything in the Hooks callback function for the test. This error is happening in the forminator core, if you look error track carefully you will see that. For more information please test yourself. also, enable the error log in WordPress. I checked all your marked points. please kindly let me know the updates

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @javmah

    Thank you for your response!

    I tried to replicate it and with “stock” version of Formiantor (by this I mean not using any additional custom code) I was not able to. I made sure that I have all the error reporting (including PHP notices and warning) enabled and test it on a clean setup with only Forminator and Twenty Twenty-Three theme active.

    Looking at the code outlined in warning messages, it look like the form in question is using both “postdata” field and user registration or login fields so I tested following types of form:

    1. a form with only postdata field (that creates posts)
    2. a login form
    3. a registration form
    4. and a registration form with postdata field added additionally

    No results.

    The only way I could replicate very similar issues (though in PHP 8 it gives a fatal error) was when I added this code to the site:

    add_filter( 'forminator_custom_form_submit_field_data', 'my_test_func' );
    function my_test_func() {
    }

    With this code I am hooking to the “forminator_custom_Form_submit_field_data” hook but in callback function I’m not handling passed parameters – which is expected, so that triggers fatal error.

    If I modify it like this

    add_filter( 'forminator_custom_form_submit_field_data', 'my_test_func', 10, 2 );
    function my_test_func( $form_data, $form_id) {
    }

    it’s still similar because even though parameters are passed to callback function, the callback function is not returning anything – and since it’s a filter hook it must return some data, otherwise whatever data is supposed to be filtered through this hook will simply be missing and that would cause consequences.

    But if I make the callback function return data

    add_filter( 'forminator_custom_form_submit_field_data', 'my_test_func' );
    function my_test_func( $form_data, $form_id) {
    return $form_data;
    }

    there is no more errors and it works fine.

    ——

    I’ve wrote above because I can’t really replicate the issue in any other way and I’m not sure what exactly do you man by “I didn’t write anything in the Hooks callback function for the test.” – is it that you didn’t add any custom code at all or that you did try to use that hook but the callback function was empty.

    If it’s the latter, then it would fall under the scenario described above and explain the issue (the filter hook callback function must return received data – you may skip doing anything with that data and return it unchanged but you need to return it).

    —-

    If that’s not the case and you have not added any custom code whatsoever, then please:

    1. do a full conflict test on site to make sure that no other plugin is interfering
    2. and if conflict test doesn’t indicate any plugin involved, do export the form from your site and share it with us to check.

    To export form:
    – go to the “Forminator -> Forms” page and click on a little “gear” icon next to the form in question
    – select “Export” option and copy given code
    – paste copied code into a new “paste” at https://pastebin.com
    – and post a link to it in your response below.

    Best regards,
    Adam

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @javmah ,

    It looks like Adam’s suggestion helped to solve the problem. I will mark this topic as resolved then.

    kind regards,
    Kasia

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘forminator_custom_form_submit_field_data is not working. Showing error !’ is closed to new replies.