| 1 |
<?php |
| 2 |
defined('ABSPATH') || die(); |
| 3 |
|
| 4 |
class HashFormFieldUrl extends HashFormFieldType { |
| 5 |
|
| 6 |
protected $type = 'url'; |
| 7 |
|
| 8 |
protected function field_settings_for_type() { |
| 9 |
return array( |
| 10 |
'advanced_validation' => true, |
| 11 |
'clear_on_focus' => true, |
| 12 |
'invalid' => true, |
| 13 |
); |
| 14 |
} |
| 15 |
|
| 16 |
public function validate($args) { |
| 17 |
$errors = array(); |
| 18 |
|
| 19 |
$value = $args['value']; |
| 20 |
if (trim($value) == 'http://' || empty($value)) { |
| 21 |
$value = ''; |
| 22 |
} else { |
| 23 |
$value = esc_url_raw($value); |
| 24 |
$value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://' . $value; |
| 25 |
} |
| 26 |
|
| 27 |
if (!empty($value) && !preg_match('/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value)) { |
| 28 |
$errors['field' . $args['id']] = apply_filters('hashform_translate_string', HashFormFields::get_error_msg($this->field, 'invalid'), 'Hash Form', HashFormBuilder::get_form_title($args['form_id']) . ' - ' . $args['id'] . ' - ' . 'Email Auto Responder Subject'); |
| 29 |
} |
| 30 |
|
| 31 |
return $errors; |
| 32 |
} |
| 33 |
|
| 34 |
public function sanitize_value(&$value) { |
| 35 |
return HashFormHelper::sanitize_value('esc_url_raw', $value); |
| 36 |
} |
| 37 |
|
| 38 |
protected function input_html() { |
| 39 |
$field_type = $this->type; |
| 40 |
?> |
| 41 |
<input type="<?php echo esc_attr($field_type); ?>" <?php $this->field_attrs(); ?> /> |
| 42 |
<?php |
| 43 |
} |
| 44 |
|
| 45 |
} |
| 46 |
|