chrishajer

Make sure field value begins with http://

Mar 4th, 2013
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/custom-input-mask-for-a-valid-url#post-157749
  3. // change the 338 to your form ID
  4. add_filter('gform_pre_submission_filter_338', 'force_http');
  5. function force_http($form) {
  6.  
  7.         // change the 3 to your field ID where the URL will be entered
  8.         // change it a few lines further down as well
  9.         // trim the whitespace first, then make it lowercase
  10.         $haystack = strtolower(trim($_POST['input_3']));
  11.  
  12.         // check for http:// at the beginning of the string
  13.         $needle = 'http://';
  14.  
  15.         // if the http:// is not at the beginning of the string, add it and modify the POST value
  16.         if (substr($haystack, 0, 7) == $needle) {
  17.                 return $form;
  18.         }
  19.         else {
  20.                 $_POST['input_3'] = $needle . $haystack;
  21.                 return $form;
  22.         }
  23. }
Add Comment
Please, Sign In to add comment