• Hi,
    I’m trying on changing validation error messages, but I get always default messages. I would want to customize required, email and date validation messages. How shall I procede?
    I tried to use the same approach you use for captcha message, but I’m not lucky.
    I don’t know jQuery very well and maybe I’m getting lost in a glass of water, but this is what I’ve done:
    1) I’ve added a class to elements by their id (is it possible to add by something less specific, I mean, is it possible to get the label of the field or something?)

    $("#entry_6").addClass("gform-date");

    2) I’ve added a class rule to the class

    $.validator.addClassRules("gform-date", {
            date: true
    });

    3) then I try to put messages on validate’s options, but no way of having these messages

    $("#ss-form").validate({
            errorClass: "gform-error",
            messages: {
              date: "Custome message!"
            }
    }) ;

    How can I make it work?

    http://wordpress.org/extend/plugins/wpgform/

Viewing 1 replies (of 1 total)
  • Plugin Author Mike Walsh

    (@mpwalsh8)

    This is a pretty advanced topic that has come up before and I don’t have a good solution for. The jQuery validate plugin is pretty powerful and is excellent for doing form validation but it is difficult to create form specific rules in the general case.

    What I mean by this that is Google Forms doesn’t know that you’re asking your user for an email address. To Google Forms, you simply have a text entry box with a label and possibly a help message. The form element for an email address is no different than the form element any other text input. This makes creating a general purpose rule hard and right now, beyond the scope of what WordPress Google Form can do.

    That said, there is nothing preventing you from writing your own plugin to validate the form for your specific instance.

    From your post it looks like you are trying to modify my plugin to add some form specific validation which while it will likely work if you only have one form, would also affect any other form that might be used on your site.

    If you want to add form specific validation, you might be better off writing a separate plugin that can define rules for the specific fields on your form. Yes, you are correct that you’d use the element IDs (e.g. entry_6). The risk you run by modifying my plugin is having to incorporate your changes when I release updates.

    In principal, what you’ve posted above appears to be generally correct. With jQuery getting the selector correct can sometimes be 90% of the work. When you ran the code your posted above, did you verify that the “gform-date” class was added to the entry_6 field? That is the first thing to check because if that hasn’t happened, then the validation will never be triggered.

Viewing 1 replies (of 1 total)
  • The topic ‘Customizing inline validation messages’ is closed to new replies.