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.

Check if two email fields are equal

  1. Jan Egbert
    Member

    I've noticed that annoying forms that want me to type my email address twice are not as useless as they seem. For a subscription form that has been filled out hundreds of times now, many people made a mistake in the email address.

    So I made a form that has two required email fields. Now I'm looking for a simple way to check if these two fields contain the same value before accepting submitting of the form. Would this be possible with one of the hooks?

    Posted 14 years ago on Saturday January 30, 2010 | Permalink
  2. I have forwarded this request to Alex who will be able to answer it better. I know you can use the hooks to compare the two fields, however i'm not 100% sure on the validation side of things. Alex will be able to answer this question better... so keep an eye out for his response.

    Posted 14 years ago on Sunday January 31, 2010 | Permalink
  3. Jan,
    Unfortunately we don't have a hook that allows you to have custom validation. We have had this request before and It is on my list for 1.4, but we don't have a timeframe for that version yet.
    What you could do is use jQuery and perform the validation with javascript. It is not bullet proof or very pretty, but it might do the trick for you.
    If you are interested in trying that approach, I can help you with a code snippet.

    Posted 14 years ago on Sunday January 31, 2010 | Permalink
  4. Jan Egbert
    Member

    Thanks Alex,

    1. It would be a cool feature for the Advanced tab of the email field.
    2. I'm not at all familiar with jQuery, so I could use a code snippet to get started.

    Posted 14 years ago on Sunday January 31, 2010 | Permalink
  5. Jan Egbert
    Member

    I did find this snippet. It looks pretty simple...

    $("#myform").validate({
      rules: {
        email: "required",
        email_again: {
          equalTo: "#email"
        }
      }
    });
    Posted 14 years ago on Sunday January 31, 2010 | Permalink
  6. Jan Egbert
    Member

    I tried this method: http://docs.jquery.com/Plugins/Validation/Methods/equalTo

    $("#gform_1").validate({
      rules: {
    	input_4: "required",
    	input_19: {
          equalTo: "#input_1_4"
        }
      }
    });

    Added some CSS, but so far I haven't been able to get it to work. Although it looks pretty straight forward.

    Posted 14 years ago on Sunday January 31, 2010 | Permalink
  7. Jan,
    I couldn't get the validation plugin to work neither, but the following should do the trick. A little bit more complex, but not too bad. Just make sure you include the jQuery library on that page. Let me know how it goes.

    jQuery(document).ready(function(){
                    jQuery("input.button").click(
                        function(){
                            if(jQuery("#input_1_4").val() != jQuery("#input_1_19").val())
                            {
                                jQuery("#field_1_19").addClass("gfield_error");
                                jQuery("#field_1_19 .validation_message").remove();
                                jQuery("#field_1_19 .ginput_container").append("<div class='gfield_description validation_message'>Your emails do not match.</div>");
                                return false;
                            }
                        }
                    );
                });
    Posted 14 years ago on Tuesday February 2, 2010 | Permalink
  8. Jan Egbert
    Member

    Works fine! Thanks.

    I used Justin Tadlock's Javascript Logic plugin to load jquery for the page where the form is embedded.

    Posted 14 years ago on Wednesday February 3, 2010 | Permalink
  9. Good stuff Jan!
    I am glad it worked for you.

    Posted 14 years ago on Wednesday February 3, 2010 | Permalink
  10. rzn8media
    Member

    You could use the jQuery Form Plugin to utterly hi-Jack the form on submit, use the ajaxSubmit or ajaxForm options and the validate plugin to do all the custom validation, and then you could use the "return false" to prevent GravityForms from handling it at all.

    I don't know if you have used the jquery forms plugin much Alex.. Has anyone tried this before?

    Posted 14 years ago on Sunday May 30, 2010 | Permalink
  11. digitalleap
    Member

    I also came here looking for a solution, preferably one that allowed me to be flexible and have it run over many forms. I took the code by Alex and did a bit of hacking on it so that I could "enable" the confirmation in the backend.

    jQuery(document).ready(function(){
        jQuery("input.button").click(
            function(){
                if(jQuery(".email input").val() != jQuery(".confirm-email input").val())
                {
                    jQuery(".confirm-email").addClass("gfield_error");
                    jQuery(".confirm-email .validation_message").remove();
                    jQuery(".confirm-email .ginput_container").append("<div class='gfield_description validation_message'>Your emails do not match.</div>");
                    return false;
                }
            }
        );
    });

    So now all you need to do is create an email field and give it a class name of "email" in the advanced tab and then create a single line text field (people do not need to be told twice that they have not entered a valid email) and give it the class name "confirm-email".

    What you guys think?

    Only down side is that the validation run before the rest of the form validation but at least it is there.

    Posted 14 years ago on Tuesday June 8, 2010 | Permalink
  12. This solves my needs short term, but the custom validation that has been mentioned in several threads as a 'coming feature' would be something I'd put a +1 vote towards on the feature request list side of things.

    Posted 14 years ago on Wednesday September 22, 2010 | Permalink
  13. Morten Knudsen
    Member

    +1

    Posted 14 years ago on Thursday September 23, 2010 | Permalink
  14. pcohen15
    Member

    +1

    Posted 14 years ago on Thursday September 23, 2010 | Permalink
  15. +1

    Posted 14 years ago on Wednesday September 29, 2010 | Permalink

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