prashantcs053
7/3/2017 - 1:36 PM

check_website_field_value for all form fields if value does not start with ftp:// http:// or https:// and add http:// to start of value

check_website_field_value for all form fields if value does not start with ftp:// http:// or https:// and add http:// to start of value

add_filter('gform_pre_render', 'form_check_website_field_value');
add_filter('gform_pre_validation', 'form_check_website_field_value');

function form_check_website_field_value($form) {
    foreach ($form['fields'] as &$field) {  // for all form fields
        if ('website' == $field['type'] || ( isset($field['inputType']) && 'website' == $field['inputType'])) {  // select the fields that are 'website' type
            $value = RGFormsModel::get_field_value($field);  // get the value of the field
            if (!empty($value)) { // if value not empty
                $field_id = $field['id'];  // get the field id
                if (!preg_match("~^(?:f|ht)tps?://~i", $value)) {  // if value does not start with ftp:// http:// or https://
                    $value = "http://" . $value;  // add http:// to start of value
                }
                $_POST['input_' . $field_id] = $value; // update post with new value
            }
        }
    }
    return $form;
}