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.

How to check a field for a specific word using gform validation?

  1. Hello,
    I'm building a membership site for a client. It's a paid site, and using s2member to control registrations. The catch is, he wants to be able to give out code(s) that would allow for free multiple month trials, without requiring the user to pay / signup afterwards. There isn't any way to do this s2member, other than using a free registration form. The obvious fallback to that, is he only wants people with the codes to have access to the free registration forms, not open to everyone...

    Hence, I would like to use a simple Gravity Form on it's own page, asking the user to input their voucher code, and if that voucher code matches, accept it and redirect the user to the free registration form.

    gform validation sounds like exactly what I need to do this, but I'm not sure how to modify the VIN example shown here http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook in the documentation.

    It would only need to check one form field, for any of 3 possible hard-coded voucher codes, say, 'CODE-1', 'CODE-2' or 'CODE-3'

    I assume the function for pulling the input data in the example remains the same, it's the check for function is_vin($vin) { that would need revised to check against a couple possible codes.

    Would this be easy to modify?
    Thanks for your thoughts, Jonathon

    Posted 12 years ago on Sunday January 22, 2012 | Permalink
  2. No thoughts on this?

    Posted 12 years ago on Monday January 30, 2012 | Permalink
  3. petitshoo
    Member

    Did you ever figure this out? I'm trying to do the same thing, but the documentation provided doesn't help me much (I'm not a php programmer...I know enough to get in trouble).

    Thanks!

    Posted 12 years ago on Friday April 20, 2012 | Permalink
  4. petitshoo
    Member

    Okay, so I'm adding the PHP code from the Documentation section (http://www.gravityhelp.com/documentation/page/Gform_field_validation). However, I want to target a word, not a number. I am a novice at PHP and don't know what I should be using for this line in the validation since I am not using a number:

    if($result["is_valid"] && intval($value) > 10){

    Please help soon! I have to have this complete very quickly.
    Thanks!

    Posted 12 years ago on Friday April 20, 2012 | Permalink
  5. David Peralty

    This might help you understand how to do comparisons in PHP - http://php.net/manual/en/language.operators.comparison.php

    Posted 12 years ago on Friday April 20, 2012 | Permalink
  6. petitshoo
    Member

    So, the line in the code would look like this?

    if($result["is_valid"] && $a === $b($value)){

    And where do I define the words I want to validate? In place of the b?

    Thanks for your help! I think I'm in over my head.

    Posted 12 years ago on Friday April 20, 2012 | Permalink
  7. petitshoo, I haven't messed with this myself yet, and I'm no PHP expert, but you might want to try something like:

    if($result["is_valid"] && $a == "hello"){

    hello, being your term you're comparing the variable to. Hope this works for you.

    Posted 12 years ago on Monday April 23, 2012 | Permalink