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 date greater than 18 yrs

  1. Hi am trying to validate the from to check that the date entered by the user is greater than 18 yrs as its the DOB and we dont allow people that are under age.

    I was wondering if someone would know how to do this
    Thanks

    Posted 12 years ago on Tuesday December 27, 2011 | Permalink
  2. Currently there isn't a built in way to do this.

    The only way you could do this is by writing some custom validation using the gform_validation hook to get the value of the field you are using for them to select their date of birth, and then calculate to see if they are old enough and either throw a validation error if they are not old enough... or do nothing and allow it to continue processing if they are.

    A tutorial on how to use the gform_validation hook can be found here:

    http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook

    Posted 12 years ago on Wednesday December 28, 2011 | Permalink
  3. Carl, waking this one up, I've been trying to follow along with your VIN checker example, but to create this "age checker". Basically, I want to know if a date entered is at least 13 years ago (ie, to check if the person is 13 or older). I've got the following code all worked out by following your tutorial & reading up on comparing date strings in PHP...but alas, it's not working so I'm assuming I've missed something vital here:

    http://pastie.org/5688714

    Any chance you could take a quick gander at that and let me know if I'm on the right track and/or where I might be slipping up?

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  4. Can you post a link to your form please? I'm just curious which field holds the date.

    The code you posted looks overly complex so I was going to try to simplify a little bit. If you would like, you can export the form as XML and email it to me at chris@rocketgenius.com

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  5. Nathan, please take a look at this code and let me know if you have any questions. I used this code with your form (which was form 274 in my installation) and it fails validation with a birthday of January 17, 2000 (just one day away from 13th birthday) and passes validation with a date of birth of January 16, 2000.

    http://pastebin.com/Rz9hurZt

    I added the "You're $age years old." part of the validation error message purely as debugging. You can remove that.

    Posted 11 years ago on Wednesday January 16, 2013 | Permalink
  6. Well thank you very much, Chris! Worked perfectly. :)

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  7. Awesome. Thank you for the confirmation. I'll leave this topic open for others as I know this solution has been requested before.

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  8. Hey Chris,

    I'm stalking Nathan here ...

    Where does this code reside? I can follow the example, but it's not clear to me where it should go.

    Nathan here had a blog post about the issue, and /wp-includes/functions.php would error.
    For my installation I've tried /wp-content/themes/ultimatum/functions.php - this doesn't error but the filter doesn't seem to fire.

    I'm certain the form id and input/field are correct.

    Any suggestions to help debug this?

    Thanks,

    Posted 11 years ago on Friday February 22, 2013 | Permalink
  9. That code resides in your theme's functions.php. Sounds like this is correct: /wp-content/themes/ultimatum/functions.php

    If it doesn't seem to fire, something is wrong with it. Can you be sure it is being applied to this form by echoing something, just to see if the code is run? Even:

    [php]
    echo "Hello.  It works";

    right on line 6. Once you're sure the code is being processed, we can see why it's not working for you.

    Posted 11 years ago on Saturday February 23, 2013 | Permalink
  10. Hey Chis,

    I'm ahead of ya .. I'm debugging it now. It's firing, so I think it's in the right place. I"ll let you know where I get.

    Thank you for the quick response!

    Posted 11 years ago on Saturday February 23, 2013 | Permalink
  11. You're welcome. Let us know what you find out.

    Posted 11 years ago on Saturday February 23, 2013 | Permalink
  12. Looks like it's breaking here:

    // retrieve the $form
    $form = $validation_result['form'];

    I can't get $form value to print.

    Posted 11 years ago on Saturday February 23, 2013 | Permalink
  13. Please post all your code and we will take a look. Please use pastebin.com or pastie.org.

    Posted 11 years ago on Saturday February 23, 2013 | Permalink
  14. Hey Chris,

    I decided to go on vacation in Hawaii for 2 weeks, get a tan, and give you some more time to research my problem. I know you have been working on this the whole time I was away so I'm eager for your response.

    Here's the code in functions.php for the active theme:

    http://pastie.org/private/op4hf2gm9h8xagn29ru1pw

    Here's the url where I'm testing this:

    http://ferrara.brickfish.com/age-gate/

    As you can see the filter appears to function correctly as the javascript debugging message will show up, but firebug console is spitting out this error:

    referenceError: $form is not defined

    Maybe my brain isn't working yet back from vacation but I'm not following that ...

    Should I declare that form variable and set it to the gravity form id?

    Any tips?

    P.S. I'm not a php whiz so debugging this isn't up my alley.

    Thank you sir.

    Posted 11 years ago on Wednesday March 13, 2013 | Permalink
  15. One thing I noticed when looking at your page is that there is a bunch of extra markup where the Gravity Form is output. Take a look at the source of that page (when not logged in) around lines 572 to 581. There are extra < br > tags and closing < p > tags in there which are not coming from Gravity Forms. Those are coming from a theme or plugin on your site. Please see these topics for people who have had similar problems: http://www.gravityhelp.com/forums/tags/raw

    The quick fix may be to wrap the [gravityform id=5 ajax="true"] shortcode in the [raw] shortcode like this:

    [php]
    [raw][gravityform id=5 title="false" description="false" ajax="true"][/raw]

    Once you get rid of that extra markup, we'll take another look.

    If you can't figure out where the extra HTML is coming from, please use our theme and plugin conflict resolution steps http://rkt.gs/testing

    Posted 11 years ago on Thursday March 14, 2013 | Permalink
  16. Chris,

    I have also been looking in to this feature for a while now and having some issues. Wondering if you could tell me if either of these 2 items would cause this to be an issue:

    1. My registration form is a multi step process.
    2. My birthday field is a calendar/date picker.

    Wondering if that would cause any issues.

    Thank you!

    Posted 11 years ago on Monday March 18, 2013 | Permalink
  17. Danny, for multi-page forms, the gform_validation filter requires a little more work. Please see the documentation here:
    http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook#Getting_the_Current_Page

    Item 2 will only require you convert the date format so it's the same format as what you're comparing it to. There are PHP functions to translate the date format before you make you comparison (strtotime).

    http://php.net/manual/en/function.strtotime.php

    Other than that, I can't see any problems with your application.

    Posted 11 years ago on Tuesday March 19, 2013 | Permalink