PluginProbe
Hello Plus / 1.4.0
Hello Plus v1.4.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / trunk / modules / forms / fields / tel.php

tel.php in Hello Plus 1.4.0, at trunk/modules/forms/fields/tel.php

40 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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