PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

No Duplicates - custom validation message

  1. stephan.wehmeier
    Member

    I applied the No Duplicates rule to an e-mail form field.

    I want to change the error message
    "This field requires an unique entry and 'email@address.com' has already been used"
    but only for this form and this field.

    I guess changing the message can be done with some add_filter hook, but how can I limit the hook to the specific form and field?

    Posted 13 years ago on Saturday February 19, 2011 | Permalink
  2. By default the custom validation message that is entered under the Advanced tab of the field editor should override the default validation message. But in the case of the no duplicates option, it doesn't appear to be doing so. I will look into why and get it changed so that the custom validation message does override the default in this situation.

    There is also a hook that can be used to implement custom validation. It is called the gform_validation hook.

    Here is an example of it's use:

    <?php
    add_filter('gform_validation', 'custom_validation');
    function custom_validation($validation_result){
    
        // set the form validation to false
        $validation_result["is_valid"] = false;
        $form = $validation_result["form"];
    
        // specify the first field to be invalid and provide custom validation message
        $form["fields"][0]["failed_validation"] = true;
        $form["fields"][0]["validation_message"] = "This field is invalid!";
    
        // update the form in the validation result with the form object you modified
        $validation_result["form"] = $form;
    
        return $validation_result;
    }
    ?>
    Posted 13 years ago on Saturday February 19, 2011 | Permalink
  3. stephan.wehmeier
    Member

    I think that you need two different validation messages for a field if two rules (required, no duplicates) are applied to one form field.
    The field editor override in the advanced tab seems to be applied to the required-rule, but not to the duplicate-rule - what makes sense: two rules, two messages.

    Posted 13 years ago on Saturday February 19, 2011 | Permalink
  4. Well by default the custom message under the Advanced tab is supposed to override ANY and ALL default validation messages. That includes the required field validation message and the no duplicates message. It should override both.

    That is how the functionality is supposed to work but I will have to look into why the custom validation message feature isn't overriding the no duplicates default message.

    Posted 13 years ago on Saturday February 19, 2011 | Permalink
  5. stephan.wehmeier
    Member

    Can I do something like this

    add_filter('gform_dupli_validation_message', 'change_message', 10, 2);
    function change_message($message, $form){
    return 'Custom Error Message';
    }

    or do I really need to rebuild the whole No Duplicate script just to change the text oft the error message?
    If this is the case, are there examples of how to recode the No Duplicate script? Any Hints?

    Posted 13 years ago on Saturday February 19, 2011 | Permalink
  6. Outside of the gform_validation hook, there isn't a hook just to change the validation message. That is what the custom validation message option is for and it will be corrected in the next release to override the no duplicates validation message as well as the required field message. So I would suggest waiting for the next release and using the custom validation message option which is what it is designed for.

    Posted 13 years ago on Saturday February 19, 2011 | Permalink
  7. Hi Carl,

    Any updates about this? I also would like to change the validation message in the no-duplicate field in my form. Thanks!

    Posted 12 years ago on Wednesday February 8, 2012 | Permalink
  8. Hi Carl, I second this to, would be useful

    For future versions, it would be good to put a another validation message input underneath the first validation message input, but only if the 'no duplicates' option is selected. Also have it so the duplicate email variable can be used.

    Posted 12 years ago on Tuesday February 28, 2012 | Permalink
  9. Has there been any update with this?

    Many thanks!

    Posted 12 years ago on Wednesday September 26, 2012 | Permalink
  10. In version 1.6.10, this is still an issue. I.e., Carl's remarks above about how the custom validation message should override the validation message when there's a duplicate error, but this is not the case. Any update on how to change the validation message for duplicate field entries?

    Posted 11 years ago on Tuesday December 11, 2012 | Permalink
  11. Closing this as a duplicate of your new topic here:
    http://www.gravityhelp.com/forums/topic/change-no-duplicate-validation-message-on-email-field

    Posted 11 years ago on Wednesday December 19, 2012 | Permalink

This topic has been resolved and has been closed to new replies.