PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.20
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.20
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/fields/FrmFieldName.php +5 -81 6.276.20 View file →
@@ -2,9 +2,8 @@
2 2 /**
3 3 * Name field
4 4 *
5 5 * @package Formidable
6 - *
7 6 * @since 4.11
8 7 */
9 8
10 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -13,19 +12,11 @@
13 12
14 13 class FrmFieldName extends FrmFieldCombo {
15 14
16 15 /**
17 - * Track the first name field ID in forms.
18 - *
19 - * @var array Array with keys are form ID and values are name field IDs.
20 - */
21 - private static $first_name_field_ids = array();
22 -
23 - /**
24 16 * Field name.
25 17 *
26 18 * @var string
27 - *
28 19 * @since 3.0
29 20 */
30 21 protected $type = 'name';
31 22
@@ -32,9 +23,8 @@
32 23 /**
33 24 * Could this field hold email values?
34 25 *
35 26 * @var bool
36 - *
37 27 * @since 3.0
38 28 */
39 29 protected $holds_email_values = true;
40 30
@@ -63,10 +53,11 @@
63 53 protected function get_processed_sub_fields() {
64 54 $name_layout = $this->get_name_layout();
65 55 $names = explode( '_', $name_layout );
66 56 $col_class = 'frm' . intval( 12 / count( $names ) );
67 - $result = array();
68 57
58 + $result = array();
59 +
69 60 foreach ( $names as $name ) {
70 61 if ( empty( $this->sub_fields[ $name ] ) ) {
71 62 continue;
72 63 }
@@ -91,13 +82,11 @@
91 82 * @return string
92 83 */
93 84 protected function get_name_layout() {
94 85 $name_layout = FrmField::get_option( $this->field, 'name_layout' );
95 -
96 86 if ( ! $name_layout ) {
97 87 $name_layout = 'first_last';
98 88 }
99 -
100 89 return $name_layout;
101 90 }
102 91
103 92 /**
@@ -139,9 +128,8 @@
139 128 * This also handles the shortcode output. Support [id], [id show=first], [id show=last], [id show=middle].
140 129 *
141 130 * @param mixed $value Field value before processing.
142 131 * @param array $atts Shortcode attributes.
143 - *
144 132 * @return string Most of cases, this will return string.
145 133 */
146 134 protected function prepare_display_value( $value, $atts ) {
147 135 if ( ! is_array( $value ) ) {
@@ -150,9 +138,9 @@
150 138
151 139 $name_layout = $this->get_name_layout();
152 140
153 141 if ( ! empty( $atts['show'] ) ) {
154 - return $value[ $atts['show'] ] ?? '';
142 + return isset( $value[ $atts['show'] ] ) ? $value[ $atts['show'] ] : '';
155 143 }
156 144
157 145 $value = wp_parse_args(
158 146 $value,
@@ -181,10 +169,8 @@
181 169
182 170 /**
183 171 * @since 4.0.04
184 172 *
185 - * @param array|string $value
186 - *
187 173 * @return void
188 174 */
189 175 public function sanitize_value( &$value ) {
190 176 FrmAppHelper::sanitize_value( 'sanitize_text_field', $value );
@@ -193,9 +179,8 @@
193 179 /**
194 180 * Validate field.
195 181 *
196 182 * @param array $args Arguments. Includes `errors`, `value`.
197 - *
198 183 * @return array Errors array.
199 184 */
200 185 public function validate( $args ) {
201 186 /**
@@ -265,15 +250,12 @@
265 250 *
266 251 * @since 6.16
267 252 *
268 253 * @param array $args
269 - *
270 254 * @return void
271 255 */
272 256 public function show_after_default( $args ) {
273 - echo '<div class="frm-mt-xs">';
274 257 parent::show_after_default( $args );
275 - echo '</div>';
276 258
277 259 /**
278 260 * @var array $field
279 261 */
@@ -279,12 +261,10 @@
279 261 */
280 262 $field = $args['field'];
281 263
282 264 $show_warning = false;
283 -
284 - foreach ( $this->sub_fields as $sub_field ) {
265 + foreach ( $this->sub_fields as $name => $sub_field ) {
285 266 $description = FrmField::get_option( $field, $sub_field['name'] . '_desc' );
286 -
287 267 if ( in_array( $description, array( 'First', 'Last' ), true ) ) {
288 268 $show_warning = true;
289 269 break;
290 270 }
@@ -295,68 +275,12 @@
295 275 }
296 276 ?>
297 277 <div class="frm_warning_style">
298 278 <?php
299 - FrmAppHelper::icon_by_class( 'frmfont frm_alert_icon', array( 'style' => 'width:24px' ) );
279 + FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon', array( 'style' => 'width:24px' ) );
300 280 echo ' ';
301 281 esc_html_e( 'Subfield descriptions are read by screen readers. Enhance accessibility by using complete labels, like "First Name" instead of "First".', 'formidable' );
302 282 ?>
303 283 </div>
304 284 <?php
305 - }
306 -
307 - /**
308 - * Tracks the first name field ID in a form.
309 - *
310 - * @since 6.26
311 - *
312 - * @param object[] $fields Array of fields in a form.
313 - *
314 - * @return void
315 - */
316 - public static function track_first_name_field( $fields ) {
317 - foreach ( $fields as $field ) {
318 - if ( 'name' === $field->type ) {
319 - self::$first_name_field_ids[ $field->form_id ] = $field->id;
320 - return;
321 - }
322 - }
323 - }
324 -
325 - /**
326 - * Gets subfield input attributes.
327 - *
328 - * @since 6.26
329 - *
330 - * @param array $sub_field Subfield data.
331 - * @param array $args Field output args. See {@see FrmFieldCombo::load_field_output()}.
332 - *
333 - * @return array
334 - */
335 - protected function get_sub_field_input_attrs( $sub_field, $args ) {
336 - $attrs = parent::get_sub_field_input_attrs( $sub_field, $args );
337 - $form_id = (int) ( is_array( $args['field'] ) ? $args['field']['form_id'] : $args['field']->form_id );
338 -
339 - if ( ! self::$first_name_field_ids || empty( self::$first_name_field_ids[ $form_id ] ) ) {
340 - return $attrs;
341 - }
342 -
343 - $parent_form_id = (int) FrmField::get_option( $args['field'], 'parent_form_id' );
344 -
345 - if ( $form_id !== $parent_form_id ) {
346 - // Do not add autocomplete attribute to a name field inside repeater.
347 - return $attrs;
348 - }
349 -
350 - $field_id = (int) ( is_array( $args['field'] ) ? $args['field']['id'] : $args['field']->id );
351 -
352 - if ( intval( self::$first_name_field_ids[ $form_id ] ) === $field_id ) {
353 - if ( 'first' === $sub_field['name'] ) {
354 - $attrs['autocomplete'] = 'given-name';
355 - } elseif ( 'last' === $sub_field['name'] ) {
356 - $attrs['autocomplete'] = 'family-name';
357 - }
358 - }
359 -
360 - return $attrs;
361 285 }
362 286 }