• Resolved meushar

    (@meushar)


    I am using add_filter(‘forminator_custom_form_submit_field_data’, ‘test_piapi_interface’, 10, 2); to process the form. In ‘test_piapi_interface’, i determine field which I write to the form field_data_array. The data written is displayed in the submission table for the form, bug NOT onscreen

    I now want to use those fields for the redirection. I have tried many different solutions but I cannot get any javasript eventlistiners to work like

    document.addEventListener(‘forminator:form:submit:success’, function(event) {

                console.log(“✅ Form submitted via AJAX”);

    i cant find any documentation on forminator hooks either. ChatGPT has been leading me in circles. Please can you advise

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @meushar

    Hope you are doing well today.

    Your code should work, but to make sure it will work as expected, please make sure you are using the Ajax submission method in form settings.

    View post on imgur.com

    You can read this document to learn more, we have shared an example Javascript code that will trigger when you submit the form.
    https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#form-data-not-sent-to-gtm

    If you still have issues, please let us know.

    Best Regards
    Amin

    Thread Starter meushar

    (@meushar)

    Hi Amin

    with a huge amount of effort I managed to come up with the names of appropriate hooks to use for pre and post submit processing. I am now at the last stage where I need to return the new data values for the fields to the front end.

    My backend code writes the response, but I cannot retrieve it on the front end. I obviously have the incorrect parameters for the functions, and even the incorrect jquery parameters. Please can you assist?

    My backend in functions.php is

    add_filter(‘forminator_form_ajax_submit_response’, function($response_data, $form_id) {

        error_log(“✅ Hook forminator_form_ajax_submit_response FIRED for form ID: $form_id”);

        error_log(“Before modification: ” . print_r($response_data, true));

        if ($form_id == 79 && isset($GLOBALS[‘piapi_updated_values’])) {

            $response_data[‘data’][‘piapi_update’] = $GLOBALS[‘piapi_updated_values’];

            error_log(“Injected piapi_update: ” . print_r($GLOBALS[‘piapi_updated_values’], true));

        }

        error_log(“After modification: ” . print_r($response_data, true));

        return $response_data;

    }, 10, 2);

    My front end code is

    jQuery(document).on('forminator:form:submit:success', function(event) {

        // Try to get data from originalEvent.detail or event.detail (native custom event)

        var detail = event.originalEvent?.detail || event.detail;

        console.log("🔥 Form submitted");

        console.log("📥 event detail:", detail);

        if (detail && detail.data && detail.data.piapi_update) {

            console.log("✅ piapi_update found:", detail.data.piapi_update);

            var form = event.target;

            Object.entries(detail.data.piapi_update).forEach(function([name, value]) {

                var input = form.querySelector(
    [name="${name}"]);

                if(input) {

                    input.value = value;

                    console.log(🧠 Updated field ${name} to ${value});

                }

            });

        } else {

            console.warn("⚠️ No piapi_update found in AJAX response");

        }

    });

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @meushar,

    Hope you’re doing well today!

    I am further checking this with our Forminator devs to see if they can review your code and suggest about this. However, please note that sharing fully working custom snippets will be out of the scope of support that we can provide.

    That said, we will keep you posted here as soon as we receive further insights from the Devs. Thank you for your patience.

    Kind Regards,
    Saurabh

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @meushar

    An update here,

    The devs were able to review the custom code you’ve added, since you are passing the data in response and trying to access it using forminator:form:submit:success, unfortunately, at the moment, there is no way to access the response there. We have this reported already to the Forminator team and they shall be working on improving it further. As of now I cannot share an exact ETA as to when the improvement will be released.

    In the meantime, can you please try setting the redirect URL in $response['url'] within the same forminator_form_ajax_submit_response hook and check if that works for you?

    Kind Regards,
    Saurabh

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @meushar,

    Since we have acknowledged this will be fixed in a future update, I’ll mark it as resolved for now.

    For any new feature updates, you can get notifications on our progress by subscribing to our roadmap at https://wpmudev.com/roadmap/

    Once new versions are released, any pertinent changes will be described in the changelog, which you can find at:

    https://ww.wp.xz.cn/plugins/forminator/#developers

    Regards,

    Nithin

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘forminator dynamic redirect url’ is closed to new replies.