| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* @since 3.0 |
| 8 |
*/ |
| 9 |
class FrmFieldEmail extends FrmFieldType { |
| 10 |
|
| 11 |
/** |
| 12 |
* @var string |
| 13 |
* @since 3.0 |
| 14 |
*/ |
| 15 |
protected $type = 'email'; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
protected $display_type = 'text'; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var bool |
| 24 |
* @since 3.0 |
| 25 |
*/ |
| 26 |
protected $holds_email_values = true; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var bool |
| 30 |
*/ |
| 31 |
protected $array_allowed = false; |
| 32 |
|
| 33 |
/** |
| 34 |
* @return bool[] |
| 35 |
*/ |
| 36 |
protected function field_settings_for_type() { |
| 37 |
return array( |
| 38 |
'size' => true, |
| 39 |
'clear_on_focus' => true, |
| 40 |
'invalid' => true, |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Validate the email format |
| 46 |
* |
| 47 |
* @param array $args |
| 48 |
* |
| 49 |
* @return array |
| 50 |
*/ |
| 51 |
public function validate( $args ) { |
| 52 |
$errors = array(); |
| 53 |
if ( $args['value'] != '' && ! is_email( $args['value'] ) ) { |
| 54 |
$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' ); |
| 55 |
} |
| 56 |
|
| 57 |
return $errors; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* @since 4.0.04 |
| 62 |
* |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public function sanitize_value( &$value ) { |
| 66 |
FrmAppHelper::sanitize_value( 'sanitize_email', $value ); |
| 67 |
} |
| 68 |
} |
| 69 |
|