Custom validation message for specific field in gravity form not working

I am trying to add custom validation message for any field, but its show only default error message.

Custom validation message

Related posts

1 comment

  1. Here’s a snippet that should fix your issue. I just ran into this myself and didn’t understand why it wasn’t working. Just drop it into your theme functions.php file.

    <?php
    
    add_filter( 'gform_field_validation', 'mytheme_fix_custom_validation', 10, 4 );
    
    /**
     * Fixes Gravity Forms Custom validation message.
     *
     * @param array  $result  The result array.
     * @param string $value   The value of the field.
     * @param array  $form    The Gravity Form array.
     * @param object $field   The form field object.
     *
     * @return array  The result array.
     */
    function mytheme_fix_custom_validation( $result, $value, $form, $field ) {
        if ( ! $result['is_valid'] && ! empty( $field->errorMessage ) ) {
            $result['message'] = $field->errorMessage;
        }
        return $result;
    }
    

    Here’s a gist in case it ever changes:
    https://gist.github.com/solepixel/c8ab2ff61ed55bffa52b5b2a21663c0f

    It uses the filter documented here:
    https://docs.gravityforms.com/gform_field_validation/

Comments are closed.