gform_validation_error_form_editor

Description

The “gform_validation_error_form_editor” is a JavaScript filter that allows the form editor validation error to be overridden.

Usage

gform.addFilter('gform_validation_error_form_editor', function (error, form, has_product, has_option) {
    // Do stuff

    return error;
});

Parameters

  • error string

    The error message.

  • form Form Object

    The Form Object.

  • has_product boolean

    Indicates if the current form has a product field.

  • has_option boolean

    Indicates if the current form has a option field.

Example

This example prevents the form from being saved if there is a product field present.

This example uses the gform_admin_pre_render filter to load the hook on the form editor page:

add_filter( 'gform_admin_pre_render', function ( $form ) {
    if ( GFCommon::is_form_editor() ) {
        echo '
            <script>
                gform.addFilter( "gform_validation_error_form_editor", function( error, form, has_product, has_option ){
                    if ( has_product ) {
                        error = "I am sorry, Dave. You are not allowed to create a form with products. Please remove the product field to save your form.";
                    }
                    return error;
                });
            </script>';
    }

    // Return the filtered form object 
    return $form;
} );

Placement

This example shows loading this JavaScript using PHP. This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in js.php.