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
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");
}
});
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
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
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