Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // http://www.gravityhelp.com/forums/topic/custom-input-mask-for-a-valid-url#post-157749
- // revised to handle multiple forms and their associated URL fields
- add_filter('gform_pre_submission_filter_338', 'force_http_prefix');
- function force_http_prefix($form) {
- $formfields = array(
- // add all your form IDs here with their corresponding field ID
- // for example, this will look for field 3 in form 338
- '338' => '3',
- '12' => '3',
- '2' => '10',
- '8' => '7'
- // for all 11 forms ...
- );
- // see if the form ID is one of the keys in our array
- // if so, then run the code to check the appropriate field
- if (array_key_exists($form['id'], $formfields)) {
- // create a variable for the input we want to modify for this form
- $input_id = 'input_' . $formfields[$form['id']];
- $haystack = strtolower(trim($_POST[$input_id]));
- // check for http:// at the beginning of the string
- $needle = 'http://';
- // if the http:// is not at the beginning of the string, add it and modify the POST value
- if (substr($haystack, 0, 7) <> $needle) {
- $_POST[$input_id] = $needle . $haystack;
- }
- }
- // return the form either way
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement