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 ) { echo GFCommon::is_form_editor() ? " <script type='text/javascript'> 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 form object from the php hook return $form; } );
Placement
This code should be placed in the functions.php file of your active theme within the gform_admin_pre_render hook.
Source Code
This filter is located in js.php.