Advertisement
Guest User

Gravity Forms Coupon Code Validation

a guest
Mar 11th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php
  2. // change 99 to the ID of the Discount Code field
  3. add_filter("gform_field_validation_99", "custom_validation", 10, 4);
  4. function custom_validation($result, $value, $form, $field){
  5.     $coupon_codes = array(
  6.     'NEWCUST20',
  7.     'RENEWCUST5',
  8.     'FREEFRIDAY'
  9.     );
  10.     $value = strtoupper($value); // make sure we are comparing apples to apples
  11.     if (!in_array($value,$coupon_codes){
  12.         $result['is_valid'] = false;
  13.         $result['message'] = 'Invalid code.';
  14.     }
  15.     return $result;
  16. }
  17. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement