Description
The gform/ajax/pre_display_error filter is triggered right before an Ajax error message is displayed. It allows developers to customize the error message shown when an Ajax form submission request fails.
Usage
gform.utils.addAsyncFilter( 'gform/ajax/pre_display_error', async ( data ) => {
// Custom logic here.
return data;
} );
Parameters
| Parameter | Type | Description |
|---|---|---|
error | string | The error message to display. |
formId | int | The ID of the form. |
submissionResult | object | The submission result. |
Examples
Customize the error message for 403 responses
gform.utils.addAsyncFilter( 'gform/ajax/pre_display_error', async ( data ) => {
if ( data.submissionResult.data.response.status === 403 ) {
const responseText = await data.submissionResult.data.response.text();
data.error = 'the custom 403 error message. response body = ' + responseText;
}
return data;
} );
Placement
Reference the article Adding JavaScript Code to the Frontend of Your Site.
Source Code
This filter is located in assets/js/src/theme/submission/ajax.js.
Since
This filter was added in Gravity Forms 2.10.1.