| 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 |
* |
| 14 |
* @since 3.0 |
| 15 |
*/ |
| 16 |
protected $type = 'email'; |
| 17 |
|
| 18 |
/** |
| 19 |
* @var bool |
| 20 |
* |
| 21 |
* @since 3.0 |
| 22 |
*/ |
| 23 |
protected $holds_email_values = true; |
| 24 |
|
| 25 |
/** |
| 26 |
* @var bool |
| 27 |
*/ |
| 28 |
protected $array_allowed = false; |
| 29 |
|
| 30 |
/** |
| 31 |
* @return bool[] |
| 32 |
*/ |
| 33 |
protected function field_settings_for_type() { |
| 34 |
return array( |
| 35 |
'size' => true, |
| 36 |
'clear_on_focus' => true, |
| 37 |
'invalid' => true, |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Validate the email format |
| 43 |
* |
| 44 |
* @param array $args |
| 45 |
* |
| 46 |
* @return array |
| 47 |
*/ |
| 48 |
public function validate( $args ) { |
| 49 |
if ( ! $args['value'] ) { |
| 50 |
return array(); |
| 51 |
} |
| 52 |
|
| 53 |
$errors = array(); |
| 54 |
|
| 55 |
if ( str_contains( $args['value'], '.@' ) || ! is_email( $args['value'] ) ) { |
| 56 |
$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' ); |
| 57 |
} |
| 58 |
|
| 59 |
return $errors; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* @since 4.0.04 |
| 64 |
* |
| 65 |
* @param array|string $value Email value passed by reference. |
| 66 |
* |
| 67 |
* @return void |
| 68 |
*/ |
| 69 |
public function sanitize_value( &$value ) { |
| 70 |
FrmAppHelper::sanitize_value( 'sanitize_email', $value ); |
| 71 |
} |
| 72 |
} |
| 73 |
|