| 1 |
<?php |
| 2 |
namespace HelloPlus\Modules\Forms\Fields; |
| 3 |
|
| 4 |
use HelloPlus\Modules\Forms\Classes; |
| 5 |
use HelloPlus\Modules\Forms\Components\Ajax_Handler; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly |
| 9 |
} |
| 10 |
|
| 11 |
class Tel extends Field_Base { |
| 12 |
|
| 13 |
public function get_type() { |
| 14 |
return 'ehp-tel'; |
| 15 |
} |
| 16 |
|
| 17 |
public function get_name() { |
| 18 |
return esc_html__( 'Tel', 'hello-plus' ); |
| 19 |
} |
| 20 |
|
| 21 |
public function render( $item, $item_index, $form ) { |
| 22 |
$form->add_render_attribute( 'input' . $item_index, 'class', 'elementor-field-textual' ); |
| 23 |
$form->add_render_attribute( 'input' . $item_index, 'pattern', '[0-9()#&+*\-=.]+' ); |
| 24 |
$form->add_render_attribute( 'input' . $item_index, 'title', esc_html__( 'Only numbers and phone characters (#, -, *, etc) are accepted.', 'hello-plus' ) ); |
| 25 |
?> |
| 26 |
<input size="1" <?php $form->print_render_attribute_string( 'input' . $item_index ); ?>> |
| 27 |
|
| 28 |
<?php |
| 29 |
} |
| 30 |
|
| 31 |
public function validation( $field, Classes\Form_Record $record, Ajax_Handler $ajax_handler ) { |
| 32 |
if ( empty( $field['value'] ) ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
if ( preg_match( '/^[0-9()#&+*-=.]+$/', $field['value'] ) !== 1 ) { |
| 36 |
$ajax_handler->add_error( $field['id'], esc_html__( 'The field accepts only numbers and phone characters (#, -, *, etc).', 'hello-plus' ) ); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|