Advertisement
chrishajer

Validation to force matching fields

Sep 18th, 2012
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/field-validation
  3. // http://www.gravityhelp.com/forums/topic/match-fields
  4. // update the 21 here to your form ID
  5. add_filter('gform_validation_21', 'matching_field_validation', 10, 2);
  6. function matching_field_validation($validation_result){
  7.  
  8.     $form = $validation_result['form'];
  9.     // this compares field 1 to field 2, update these values to match your form
  10.     if (rgpost('input_1') !== rgpost('input_2')) {
  11.         // this is the validation error for input_1
  12.         $form['fields'][0]['failed_validation'] = true;
  13.         $form['fields'][0]['validation_message'] = 'This field must match the next one.';
  14.         // this is the validation error for input_2
  15.         $form['fields'][1]['failed_validation'] = true;
  16.         $form['fields'][1]['validation_message'] = 'Please verify your entries.';
  17.         $validation_result['is_valid'] = false;
  18.     }
  19.  
  20.     // update the form in the validation result with the form object you modified
  21.     $validation_result['form'] = $form;
  22.     return $validation_result;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement