Description
The gform/ajax/post_ajax_submission
filter is used to modify the AJAX response immediately after a form is submitted via AJAX but before the response is sent to the browser. This filter allows developers to customize or modify the response data, including additional information, custom messages, or altered submission details.
Note: This filter only applies to the new AJAX submission method, which you can enable using this code snippet. Refer to this article for more information.
add_filter( 'gform_form_args', function ( $args ) {
$args['submission_method'] = GFFormDisplay::SUBMISSION_METHOD_AJAX;
return $args;
} );
Usage
Asynchronous
Use this method when the function handling this event is asynchronous. This is useful when performing tasks that involve async operations, such as AJAX requests.
gform.utils.addAsyncFilter('gform/ajax/post_ajax_submission', async (data) => {
// Custom logic here.
return data;
});
Standard
Use this method when using a standard function to handle the event (i.e., not async).
gform.utils.addFilter( 'gform/ajax/post_ajax_submission', ( data ) => {
// Custom logic here.
return data;
});
Parameters
- data JavaScript Object
- form JavaScript Object
A non filterable object representing the submitted form. - submissionResult JavaScript Object
A filterable object containing the result of the form submission.
- form JavaScript Object
Examples
Output to the JavaScript console
gform.utils.addAsyncFilter('gform/ajax/post_ajax_submission', async (data) => {
console.log('Form Data:', data.form); // Logs the form object.
console.log('Submission Result:', data.submissionResult); // Logs the submission result object.
// Your Custom Logic.
return data; // Return the modified data object
});
Placement
Your code snippet can be placed in an HTML field on your form or in a theme custom JavaScript file.
See also the JavaScript/jQuery section in this article: Where Do I Put This Code?
Source Code
This filter is located in assets/js/src/theme/submission/ajax.js
Since
The filter was added in Gravity Forms 2.9.0