class-evf-field-address.php
1 year ago
class-evf-field-ai.php
1 year ago
class-evf-field-captcha.php
1 month ago
class-evf-field-checkbox.php
3 months ago
class-evf-field-color.php
1 month ago
class-evf-field-country.php
3 months ago
class-evf-field-credit-card.php
1 month ago
class-evf-field-date-time.php
1 month ago
class-evf-field-divider.php
2 years ago
class-evf-field-email.php
1 year ago
class-evf-field-file-upload.php
1 year ago
class-evf-field-first-name.php
1 year ago
class-evf-field-hcaptcha.php
4 months ago
class-evf-field-hidden.php
1 year ago
class-evf-field-html.php
9 months ago
class-evf-field-image-upload.php
1 year ago
class-evf-field-last-name.php
1 year ago
class-evf-field-likert.php
1 year ago
class-evf-field-lookup.php
1 month ago
class-evf-field-number.php
1 year ago
class-evf-field-password.php
1 month ago
class-evf-field-payment-authorize-net.php
1 month ago
class-evf-field-payment-checkbox.php
1 month ago
class-evf-field-payment-coupon.php
1 month ago
class-evf-field-payment-gateway-selector.php
1 month ago
class-evf-field-payment-quantity.php
1 month ago
class-evf-field-payment-radio.php
1 month ago
class-evf-field-payment-single.php
1 month ago
class-evf-field-payment-square.php
1 year ago
class-evf-field-payment-subscription-plan.php
1 month ago
class-evf-field-payment-subtotal.php
1 month ago
class-evf-field-payment-total.php
1 month ago
class-evf-field-phone.php
1 year ago
class-evf-field-privacy-policy.php
3 months ago
class-evf-field-private-note.php
1 year ago
class-evf-field-progress.php
1 month ago
class-evf-field-radio.php
3 months ago
class-evf-field-range-slider.php
1 month ago
class-evf-field-rating.php
3 months ago
class-evf-field-recaptcha.php
4 months ago
class-evf-field-repeater.php
1 month ago
class-evf-field-reset.php
1 month ago
class-evf-field-scale-rating.php
1 year ago
class-evf-field-select.php
1 year ago
class-evf-field-signature.php
1 month ago
class-evf-field-text.php
1 year ago
class-evf-field-textarea.php
1 year ago
class-evf-field-title.php
2 years ago
class-evf-field-turnstile.php
4 months ago
class-evf-field-url.php
1 year ago
class-evf-field-wysiwyg.php
3 months ago
class-evf-field-yes-no.php
1 year ago
payment-amount-helpers.php
1 month ago
class-evf-field-phone.php
232 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Phone number field |
| 4 | * |
| 5 | * @package EverestForms\Fields |
| 6 | * @since 3.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * EVF_Field_Phone Class. |
| 13 | */ |
| 14 | class EVF_Field_Phone extends EVF_Form_Fields { |
| 15 | |
| 16 | /** |
| 17 | * Constructor. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | $this->name = esc_html__( 'Phone', 'everest-forms' ); |
| 21 | $this->type = 'phone'; |
| 22 | $this->icon = 'evf-icon evf-icon-phone'; |
| 23 | $this->order = 60; |
| 24 | $this->group = 'advanced'; |
| 25 | $this->settings = array( |
| 26 | 'basic-options' => array( |
| 27 | 'field_options' => array( |
| 28 | 'label', |
| 29 | 'choose_format', |
| 30 | 'description', |
| 31 | 'input_mask', |
| 32 | 'required', |
| 33 | 'required_field_message_setting', |
| 34 | 'required_field_message', |
| 35 | ), |
| 36 | ), |
| 37 | 'advanced-options' => array( |
| 38 | 'field_options' => array( |
| 39 | 'placeholder', |
| 40 | 'meta', |
| 41 | 'label_hide', |
| 42 | 'default_value', |
| 43 | 'css', |
| 44 | ), |
| 45 | ), |
| 46 | ); |
| 47 | |
| 48 | parent::__construct(); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Hook in tabs. |
| 53 | */ |
| 54 | public function init_hooks() { |
| 55 | add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Date field format option. |
| 60 | * |
| 61 | * @since 1.2.9 |
| 62 | * @param array $field Field Data. |
| 63 | */ |
| 64 | public function choose_format( $field ) { |
| 65 | $format = ! empty( $field['phone_format'] ) ? esc_attr( $field['phone_format'] ) : 'smart'; |
| 66 | $format_label = $this->field_element( |
| 67 | 'label', |
| 68 | $field, |
| 69 | array( |
| 70 | 'slug' => 'phone_format', |
| 71 | 'value' => __( 'Format', 'everest-forms' ), |
| 72 | 'tooltip' => __( 'Select a format for the phone field.', 'everest-forms' ), |
| 73 | ), |
| 74 | false |
| 75 | ); |
| 76 | $format_select = $this->field_element( |
| 77 | 'select', |
| 78 | $field, |
| 79 | array( |
| 80 | 'slug' => 'phone_format', |
| 81 | 'value' => $format, |
| 82 | 'options' => array( |
| 83 | 'default' => __( 'Default', 'everest-forms' ), |
| 84 | 'smart' => __( 'Smart', 'everest-forms' ), |
| 85 | ), |
| 86 | ), |
| 87 | false |
| 88 | ); |
| 89 | $args = array( |
| 90 | 'slug' => 'phone_format', |
| 91 | 'content' => $format_label . $format_select, |
| 92 | ); |
| 93 | $this->field_element( 'row', $field, $args ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Input mask field option. |
| 98 | * |
| 99 | * @param array $field Field Data. |
| 100 | */ |
| 101 | public function input_mask( $field ) { |
| 102 | $format = ! empty( $field['phone_format'] ) ? esc_attr( $field['phone_format'] ) : 'smart'; |
| 103 | |
| 104 | // Input Mask. |
| 105 | $input_mask_label = $this->field_element( |
| 106 | 'label', |
| 107 | $field, |
| 108 | array( |
| 109 | 'slug' => 'input_mask', |
| 110 | 'value' => esc_html__( 'Input Mask', 'everest-forms' ), |
| 111 | 'tooltip' => esc_html__( 'Enter your custom input mask.', 'everest-forms' ), |
| 112 | 'after_tooltip' => '<a href="https://docs.everestforms.net/docs/how-to-use-custom-input-mask/" class="after-label-description" target="_blank" rel="noopener noreferrer">' . esc_html__( 'See Examples & Docs', 'everest-forms' ) . '</a>', |
| 113 | ), |
| 114 | false |
| 115 | ); |
| 116 | $input_mask_field = $this->field_element( |
| 117 | 'text', |
| 118 | $field, |
| 119 | array( |
| 120 | 'slug' => 'input_mask', |
| 121 | 'value' => ! empty( $field['input_mask'] ) ? esc_attr( $field['input_mask'] ) : '(999) 999-9999', |
| 122 | ), |
| 123 | false |
| 124 | ); |
| 125 | |
| 126 | echo '<div class="format-selected-' . esc_attr( $format ) . ' format-selected">'; |
| 127 | |
| 128 | $this->field_element( |
| 129 | 'row', |
| 130 | $field, |
| 131 | array( |
| 132 | 'slug' => 'input_mask', |
| 133 | 'content' => $input_mask_label . $input_mask_field, |
| 134 | ) |
| 135 | ); |
| 136 | |
| 137 | echo '</div>'; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Define additional field properties. |
| 142 | * |
| 143 | * @since 1.0.0 |
| 144 | * |
| 145 | * @param array $properties Field properties. |
| 146 | * @param array $field Field settings. |
| 147 | * @param array $form_data Form data and settings. |
| 148 | * |
| 149 | * @return array of additional field properties. |
| 150 | */ |
| 151 | public function field_properties( $properties, $field, $form_data ) { |
| 152 | // Input primary: add validation rule and class for smart phone field. |
| 153 | if ( ! empty( $field['phone_format'] ) && 'smart' === $field['phone_format'] ) { |
| 154 | $properties['inputs']['primary']['class'][] = 'evf-smart-phone-field'; |
| 155 | $properties['inputs']['primary']['data']['rule-smart-phone-field'] = 'true'; |
| 156 | } else { |
| 157 | $properties['inputs']['primary']['data']['rule-phone-field'] = 'true'; |
| 158 | |
| 159 | if ( ! empty( $field['input_mask'] ) ) { |
| 160 | // Add class that will trigger custom mask. |
| 161 | $properties['inputs']['primary']['class'][] = 'evf-masked-input'; |
| 162 | |
| 163 | // Register string for translation. |
| 164 | $field['input_mask'] = evf_string_translation( $form_data['id'], $field['id'], $field['input_mask'], '-input-mask' ); |
| 165 | |
| 166 | if ( false !== strpos( $field['input_mask'], 'alias:' ) ) { |
| 167 | $mask = str_replace( 'alias:', '', $field['input_mask'] ); |
| 168 | $properties['inputs']['primary']['data']['inputmask-alias'] = $mask; |
| 169 | } elseif ( false !== strpos( $field['input_mask'], 'regex:' ) ) { |
| 170 | $mask = str_replace( 'regex:', '', $field['input_mask'] ); |
| 171 | $properties['inputs']['primary']['data']['inputmask-regex'] = $mask; |
| 172 | } else { |
| 173 | $properties['inputs']['primary']['data']['inputmask-mask'] = $field['input_mask']; |
| 174 | } |
| 175 | |
| 176 | // Input primary: RTL support for input masks. |
| 177 | if ( is_rtl() ) { |
| 178 | $properties['inputs']['primary']['attr']['dir'] = 'rtl'; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | return $properties; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Field preview inside the builder. |
| 188 | * |
| 189 | * @since 1.0.0 |
| 190 | * |
| 191 | * @param array $field Field data and settings. |
| 192 | */ |
| 193 | public function field_preview( $field ) { |
| 194 | |
| 195 | // Define data. |
| 196 | $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : ''; |
| 197 | |
| 198 | // Label. |
| 199 | $this->field_preview_option( 'label', $field ); |
| 200 | |
| 201 | // Primary input. |
| 202 | echo '<input type="text" placeholder="' . esc_attr( $placeholder ) . '" class="widefat primary-input" disabled>'; |
| 203 | |
| 204 | // Description. |
| 205 | $this->field_preview_option( 'description', $field ); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Field display on the form front-end. |
| 210 | * |
| 211 | * @since 1.0.0 |
| 212 | * |
| 213 | * @param array $field Field Data. |
| 214 | * @param array $field_atts Field attributes. |
| 215 | * @param array $form_data All Form Data. |
| 216 | */ |
| 217 | public function field_display( $field, $field_atts, $form_data ) { |
| 218 | // Define data. |
| 219 | $primary = $field['properties']['inputs']['primary']; |
| 220 | |
| 221 | // Allow input type to be changed for this particular field. |
| 222 | $type = apply_filters( 'everest_forms_phone_field_input_type', 'tel' ); |
| 223 | // Primary field. |
| 224 | printf( |
| 225 | '<input type="%s" %s %s>', |
| 226 | esc_attr( $type ), |
| 227 | evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] ), |
| 228 | esc_attr( $primary['required'] ) |
| 229 | ); |
| 230 | } |
| 231 | } |
| 232 |