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.

Data Validation for Coupon Codes

  1. eric_johnson
    Member

    Hello,

    I'm definitely going to purchase Gravity Forms for my e-commerce site provided I can do the following:

    I would like for the user to be able to enter a Groupon code in a Gravity Form field and have that field data validated against a database of coupon codes provided to me by Groupon. Can this be done?

    For example, the customer enters their name, address, and the Groupon code they received from their Groupon purchase and the form checks the database to see if the Groupon code is valid. If it is, the form is processed. If not, there is a notification method saying the coupon is invalid.

    Thank you.

    Posted 13 years ago on Tuesday March 8, 2011 | Permalink
  2. Gravity Forms doesn't do this out of the box as it's more specialized functionality.

    HOWEVER thats why we have API hooks/filters so you can customize the functionality without changing the core plugin code and make it do what you want to do.

    The gform_validation hook is used to apply custom validation to a field. You can use this hook to interact with the Groupon API and validate the coupon code.

    Here is an example of using the gform_validation hook:

    <?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;
    
    }
    ?>

    So this isn't something Gravity Forms does out of the box but you can write code using the gform_validation hook to implement this functionality.

    Posted 13 years ago on Tuesday March 8, 2011 | Permalink
  3. eric_johnson
    Member

    Thank you for your feedback. After doing some more research, it appears that Groupon's API doesn't yet feature/include coupon validation. They will provide me with a list of coupon numbers, but if I get this data, can I add it to my database and have Gravity Forms validate against this table?

    Posted 13 years ago on Tuesday March 8, 2011 | Permalink
  4. If they provide you with this information you could create your own database table and validate against that. With the gform_validation hook you could do virtually anything because it's custom PHP that you can write. So yes, you could do this.

    If this is outside the scope of your skill set i'd be glad to refer you to a WordPress consultant with Gravity Forms customization experience who could assist you with this. I already know one who has done coupon functionality so similar functionality has been done before.

    Posted 13 years ago on Tuesday March 8, 2011 | Permalink
  5. thanks, this validation hook is just what I was looking for ... it's not listed in the documentation at http://www.gravityhelp.com/documentation/hooks-and-filters/ ... is there a more complete list somewhere?

    thanks again!
    Donna

    Posted 13 years ago on Wednesday March 9, 2011 | Permalink
  6. We will be launching new developer documentation that will document (with examples) all of the available hooks and filters by the end of next week when we launch our new web site and the Gravity Forms v1.5 public release.

    Posted 13 years ago on Wednesday March 9, 2011 | Permalink
  7. Thanks, Carl, looking forward to it!

    Posted 13 years ago on Wednesday March 9, 2011 | Permalink

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