gform/ajax/pre_display_error

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

ParameterTypeDescription
errorstringThe error message to display.
formIdintThe ID of the form.
submissionResultobjectThe 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.