PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.18
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.18
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 +21 -93 6.336.18 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
@@ -60,12 +50,14 @@
60 50 *
61 51 * @return array
62 52 */
63 53 protected function get_processed_sub_fields() {
64 - $names = explode( '_', $this->get_name_layout() );
65 - $col_class = 'frm' . intval( 12 / count( $names ) );
66 - $result = array();
54 + $name_layout = $this->get_name_layout();
55 + $names = explode( '_', $name_layout );
56 + $col_class = 'frm' . intval( 12 / count( $names ) );
67 57
58 + $result = array();
59 +
68 60 foreach ( $names as $name ) {
69 61 if ( empty( $this->sub_fields[ $name ] ) ) {
70 62 continue;
71 63 }
@@ -90,9 +82,12 @@
90 82 * @return string
91 83 */
92 84 protected function get_name_layout() {
93 85 $name_layout = FrmField::get_option( $this->field, 'name_layout' );
94 - return $name_layout ? $name_layout : 'first_last';
86 + if ( ! $name_layout ) {
87 + $name_layout = 'first_last';
88 + }
89 + return $name_layout;
95 90 }
96 91
97 92 /**
98 93 * Gets extra field options.
@@ -133,9 +128,8 @@
133 128 * This also handles the shortcode output. Support [id], [id show=first], [id show=last], [id show=middle].
134 129 *
135 130 * @param mixed $value Field value before processing.
136 131 * @param array $atts Shortcode attributes.
137 - *
138 132 * @return string Most of cases, this will return string.
139 133 */
140 134 protected function prepare_display_value( $value, $atts ) {
141 135 if ( ! is_array( $value ) ) {
@@ -141,10 +135,12 @@
141 135 if ( ! is_array( $value ) ) {
142 136 return $value;
143 137 }
144 138
139 + $name_layout = $this->get_name_layout();
140 +
145 141 if ( ! empty( $atts['show'] ) ) {
146 - return $value[ $atts['show'] ] ?? '';
142 + return isset( $value[ $atts['show'] ] ) ? $value[ $atts['show'] ] : '';
147 143 }
148 144
149 145 $value = wp_parse_args(
150 146 $value,
@@ -154,9 +150,9 @@
154 150 'last' => '',
155 151 )
156 152 );
157 153
158 - switch ( $this->get_name_layout() ) {
154 + switch ( $name_layout ) {
159 155 case 'last_first':
160 156 $value = $value['last'] . ' ' . $value['first'];
161 157 break;
162 158
@@ -173,10 +169,8 @@
173 169
174 170 /**
175 171 * @since 4.0.04
176 172 *
177 - * @param array|string $value
178 - *
179 173 * @return void
180 174 */
181 175 public function sanitize_value( &$value ) {
182 176 FrmAppHelper::sanitize_value( 'sanitize_text_field', $value );
@@ -185,9 +179,8 @@
185 179 /**
186 180 * Validate field.
187 181 *
188 182 * @param array $args Arguments. Includes `errors`, `value`.
189 - *
190 183 * @return array Errors array.
191 184 */
192 185 public function validate( $args ) {
193 186 /**
@@ -217,17 +210,15 @@
217 210 protected function process_args_for_field_output( &$args ) {
218 211 parent::process_args_for_field_output( $args );
219 212
220 213 // Show all subfields in form builder then use JS to show or hide them.
221 - if ( ! $this->should_print_hidden_sub_fields() || count( $args['sub_fields'] ) === count( $this->sub_fields ) ) {
222 - return;
223 - }
214 + if ( $this->should_print_hidden_sub_fields() && count( $args['sub_fields'] ) !== count( $this->sub_fields ) ) {
215 + $hidden_fields = array_diff_key( $this->sub_fields, $args['sub_fields'] );
216 + $args['sub_fields'] = $this->sub_fields;
224 217
225 - $hidden_fields = array_diff_key( $this->sub_fields, $args['sub_fields'] );
226 - $args['sub_fields'] = $this->sub_fields;
227 -
228 - foreach ( $hidden_fields as $name => $hidden_field ) {
229 - $args['sub_fields'][ $name ]['wrapper_classes'] .= ' frm_hidden';
218 + foreach ( $hidden_fields as $name => $hidden_field ) {
219 + $args['sub_fields'][ $name ]['wrapper_classes'] .= ' frm_hidden';
220 + }
230 221 }
231 222 }
232 223
233 224 /**
@@ -259,15 +250,12 @@
259 250 *
260 251 * @since 6.16
261 252 *
262 253 * @param array $args
263 - *
264 254 * @return void
265 255 */
266 256 public function show_after_default( $args ) {
267 - echo '<div class="frm-mt-xs">';
268 257 parent::show_after_default( $args );
269 - echo '</div>';
270 258
271 259 /**
272 260 * @var array $field
273 261 */
@@ -273,12 +261,10 @@
273 261 */
274 262 $field = $args['field'];
275 263
276 264 $show_warning = false;
277 -
278 - foreach ( $this->sub_fields as $sub_field ) {
265 + foreach ( $this->sub_fields as $name => $sub_field ) {
279 266 $description = FrmField::get_option( $field, $sub_field['name'] . '_desc' );
280 -
281 267 if ( in_array( $description, array( 'First', 'Last' ), true ) ) {
282 268 $show_warning = true;
283 269 break;
284 270 }
@@ -286,73 +272,15 @@
286 272
287 273 if ( ! $show_warning ) {
288 274 return;
289 275 }
290 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
291 276 ?>
292 277 <div class="frm_warning_style">
293 278 <?php
294 - 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' ) );
295 280 echo ' ';
296 281 esc_html_e( 'Subfield descriptions are read by screen readers. Enhance accessibility by using complete labels, like "First Name" instead of "First".', 'formidable' );
297 282 ?>
298 283 </div>
299 284 <?php
300 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
301 - }
302 -
303 - /**
304 - * Tracks the first name field ID in a form.
305 - *
306 - * @since 6.26
307 - *
308 - * @param object[] $fields Array of fields in a form.
309 - *
310 - * @return void
311 - */
312 - public static function track_first_name_field( $fields ) {
313 - foreach ( $fields as $field ) {
314 - if ( 'name' === $field->type ) {
315 - self::$first_name_field_ids[ $field->form_id ] = $field->id;
316 - return;
317 - }
318 - }
319 - }
320 -
321 - /**
322 - * Gets subfield input attributes.
323 - *
324 - * @since 6.26
325 - *
326 - * @param array $sub_field Subfield data.
327 - * @param array $args Field output args. See {@see FrmFieldCombo::load_field_output()}.
328 - *
329 - * @return array
330 - */
331 - protected function get_sub_field_input_attrs( $sub_field, $args ) {
332 - $attrs = parent::get_sub_field_input_attrs( $sub_field, $args );
333 - $form_id = (int) ( is_array( $args['field'] ) ? $args['field']['form_id'] : $args['field']->form_id );
334 -
335 - if ( ! self::$first_name_field_ids || empty( self::$first_name_field_ids[ $form_id ] ) ) {
336 - return $attrs;
337 - }
338 -
339 - $parent_form_id = (int) FrmField::get_option( $args['field'], 'parent_form_id' );
340 -
341 - if ( $form_id !== $parent_form_id ) {
342 - // Do not add autocomplete attribute to a name field inside repeater.
343 - return $attrs;
344 - }
345 -
346 - $field_id = (int) ( is_array( $args['field'] ) ? $args['field']['id'] : $args['field']->id );
347 -
348 - if ( intval( self::$first_name_field_ids[ $form_id ] ) === $field_id ) {
349 - if ( 'first' === $sub_field['name'] ) {
350 - $attrs['autocomplete'] = 'given-name';
351 - } elseif ( 'last' === $sub_field['name'] ) {
352 - $attrs['autocomplete'] = 'family-name';
353 - }
354 - }
355 -
356 - return $attrs;
357 285 }
358 286 }