Advertisement
chrishajer

Ensure name input is letters only

Mar 14th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/name-field-1#post-169715
  3. // change the 350 here to your form ID
  4. add_filter('gform_validation_350', 'force_alpha_name', 10, 2);
  5. function force_alpha_name($validation_result){
  6.  
  7.     $form = $validation_result['form'];
  8.         // In my form, the name input is field 1, so first name is 1.3 and last is 1.6
  9.         // I put them together here to test them both at the same time
  10.         $names = rgpost('input_1_3') . rgpost('input_1_6');
  11.         if(!ctype_alpha($names)) {
  12.         $form['fields'][0]['failed_validation'] = true;
  13.         $form['fields'][0]['validation_message'] = 'Sorry, please use only letters in your name.';
  14.         $validation_result['is_valid'] = false;
  15.     }
  16.  
  17.     // update the form in the validation result with the form object you modified
  18.     $validation_result['form'] = $form;
  19.     return $validation_result;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement