PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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/FrmFieldCombo.php +15 -89 6.265.0 View file →
@@ -2,9 +2,8 @@
2 2 /**
3 3 * Combo field - Field contains sub fields
4 4 *
5 5 * @package Formidable
6 - *
7 6 * @since 4.11
8 7 */
9 8
10 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -16,9 +15,8 @@
16 15 /**
17 16 * Does the html for this field label need to include "for"?
18 17 *
19 18 * @var bool
20 - *
21 19 * @since 3.0
22 20 */
23 21 protected $has_for_label = false;
24 22
@@ -48,10 +46,8 @@
48 46 /**
49 47 * Registers sub fields.
50 48 *
51 49 * @param array $sub_fields Sub fields. Accepts array or array or array of string.
52 - *
53 - * @return void
54 50 */
55 51 protected function register_sub_fields( array $sub_fields ) {
56 52 $defaults = $this->get_default_sub_field();
57 53
@@ -75,24 +71,8 @@
75 71 ),
76 72 $defaults
77 73 );
78 74 }
79 - }//end foreach
80 - }
81 -
82 - /**
83 - * Set the aria-invalid attribute for subfields.
84 - *
85 - * @since 6.16.3
86 - *
87 - * @param array $shortcode_atts
88 - * @param array $args
89 - *
90 - * @return void
91 - */
92 - public function set_aria_invalid_error( &$shortcode_atts, $args ) {
93 - foreach ( $this->get_sub_fields() as $sub_field ) {
94 - $shortcode_atts[ 'aria-invalid-' . $sub_field['name'] ] = isset( $args['errors'][ 'field' . $this->field_id . '-' . $sub_field['name'] ] ) ? 'true' : 'false';
95 75 }
96 76 }
97 77
98 78 /**
@@ -130,10 +110,9 @@
130 110 continue;
131 111 }
132 112
133 113 foreach ( $sub_field['options'] as $option ) {
134 - if ( 'default_value' === $option ) {
135 - // We parse default value from field column.
114 + if ( 'default_value' === $option ) { // We parse default value from field column.
136 115 continue;
137 116 }
138 117
139 118 if ( is_string( $option ) ) {
@@ -151,12 +130,9 @@
151 130 * Include the settings for placeholder, default value, and sub labels for each
152 131 * of the individual field labels.
153 132 *
154 133 * @since 4.0
155 - *
156 134 * @param array $args Includes 'field', 'display'.
157 - *
158 - * @return void
159 135 */
160 136 public function show_after_default( $args ) {
161 137 $field = (array) $args['field'];
162 138 $default_value = $this->get_default_value();
@@ -164,9 +140,8 @@
164 140
165 141 foreach ( $this->sub_fields as $name => $sub_field ) {
166 142 $sub_field['name'] = $name;
167 143 $wrapper_classes = 'frm_grid_container frm_sub_field_options frm_sub_field_options-' . $sub_field['name'];
168 -
169 144 if ( ! isset( $processed_sub_fields[ $name ] ) ) {
170 145 // Options for this subfield should be hidden.
171 146 $wrapper_classes .= ' frm_hidden';
172 147 }
@@ -201,10 +176,9 @@
201 176
202 177 return $default_value;
203 178 }
204 179
205 - // We store default value as JSON string in db.
206 - return json_decode( $default_value, true );
180 + return json_decode( $default_value, true ); // We store default value as JSON string in db.
207 181 }
208 182
209 183 /**
210 184 * Gets labels for built-in options of fields or sub fields.
@@ -227,10 +201,9 @@
227 201 protected function field_settings_for_type() {
228 202 $settings = array(
229 203 'description' => false,
230 204 'default' => false,
231 - // Don't use the regular placeholder option.
232 - 'clear_on_focus' => false,
205 + 'clear_on_focus' => false, // Don't use the regular placeholder option.
233 206 'logic' => true,
234 207 'visibility' => true,
235 208 );
236 209
@@ -240,10 +213,8 @@
240 213 /**
241 214 * Shows field on the form builder.
242 215 *
243 216 * @param string $name Field name.
244 - *
245 - * @return void
246 217 */
247 218 public function show_on_form_builder( $name = '' ) {
248 219 $field = FrmFieldsHelper::setup_edit_vars( $this->field );
249 220
@@ -269,9 +240,8 @@
269 240 * Shows field in the frontend.
270 241 *
271 242 * @param array $args Arguments.
272 243 * @param array $shortcode_atts Shortcode attributes.
273 - *
274 244 * @return string
275 245 */
276 246 public function front_field_input( $args, $shortcode_atts ) {
277 247 $field = (array) $this->field;
@@ -276,9 +246,8 @@
276 246 public function front_field_input( $args, $shortcode_atts ) {
277 247 $field = (array) $this->field;
278 248
279 249 $field['default_value'] = $this->get_default_value();
280 -
281 250 if ( empty( $field['value'] ) ) {
282 251 $field['value'] = $field['default_value'];
283 252 }
284 253
@@ -304,10 +273,8 @@
304 273 * @type array $shortcode_atts Shortcode attributes.
305 274 * @type array $errors Field errors.
306 275 * @type bool $remove_names Remove name attribute or not.
307 276 * }
308 - *
309 - * @return void
310 277 */
311 278 protected function load_field_output( $args ) {
312 279 if ( empty( $args['field'] ) ) {
313 280 return;
@@ -340,10 +307,8 @@
340 307 * @type array $shortcode_atts Shortcode attributes.
341 308 * @type array $errors Field errors.
342 309 * @type bool $remove_names Remove name attribute or not.
343 310 * }
344 - *
345 - * @return void
346 311 */
347 312 protected function process_args_for_field_output( &$args ) {
348 313 $args['field'] = (array) $args['field'];
349 314
@@ -369,27 +334,24 @@
369 334 /**
370 335 * Prints sub field input atts.
371 336 *
372 337 * @param array $args Arguments. Includes `field`, `sub_field`.
373 - *
374 - * @return void
375 338 */
376 339 protected function print_input_atts( $args ) {
377 340 $field = $args['field'];
378 341 $sub_field = $args['sub_field'];
342 + $atts = array();
379 343
380 344 // Placeholder.
381 345 if ( in_array( 'placeholder', $sub_field['options'], true ) ) {
382 346 $placeholders = FrmField::get_option( $field, 'placeholder' );
383 -
384 347 if ( ! empty( $placeholders[ $sub_field['name'] ] ) ) {
385 - $field['placeholder'] = $placeholders[ $sub_field['name'] ];
348 + $atts[] = 'placeholder="' . esc_attr( $placeholders[ $sub_field['name'] ] ) . '"';
386 349 }
387 350 }
388 351
389 352 // Add optional class.
390 - $classes = $sub_field['classes'] ?? '';
391 -
353 + $classes = isset( $sub_field['classes'] ) ? $sub_field['classes'] : '';
392 354 if ( is_array( $classes ) ) {
393 355 $classes = implode( ' ', $classes );
394 356 }
395 357
@@ -397,25 +359,19 @@
397 359 $classes .= ' frm_optional';
398 360 }
399 361
400 362 if ( $classes ) {
401 - $field['input_class'] = esc_attr( $classes );
363 + $atts[] = 'class="' . esc_attr( $classes ) . '"';
402 364 }
403 365
404 - // Fake it to avoid printing frm-val attribute.
405 - $field['default_value'] = '';
406 -
407 - if ( ! empty( $sub_field['name'] ) ) {
408 - $field['subfield_name'] = $sub_field['name'];
409 - }
410 - do_action( 'frm_field_input_html', $field );
411 -
412 366 // Print custom attributes.
413 367 if ( ! empty( $sub_field['atts'] ) && is_array( $sub_field['atts'] ) ) {
414 368 foreach ( $sub_field['atts'] as $att_name => $att_value ) {
415 - echo esc_attr( trim( $att_name ) ) . '="' . esc_attr( trim( $att_value ) ) . '" ';
369 + $atts[] = esc_attr( trim( $att_name ) ) . '="' . esc_attr( trim( $att_value ) ) . '"';
416 370 }
417 371 }
372 +
373 + echo implode( ' ', $atts ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
418 374 }
419 375
420 376 /**
421 377 * Validate field.
@@ -420,13 +376,12 @@
420 376 /**
421 377 * Validate field.
422 378 *
423 379 * @param array $args Arguments. Includes `errors`, `value`.
424 - *
425 380 * @return array Errors array.
426 381 */
427 382 public function validate( $args ) {
428 - $errors = $args['errors'] ?? array();
383 + $errors = isset( $args['errors'] ) ? $args['errors'] : array();
429 384
430 385 if ( ! $this->field->required ) {
431 386 return $errors;
432 387 }
@@ -460,13 +415,12 @@
460 415 * @return array
461 416 */
462 417 public function get_export_headings() {
463 418 $headings = array();
464 - $field_id = $this->field->id ?? $this->field['id'];
465 - $field_name = $this->field->name ?? $this->field['name'];
466 - $field_key = $this->field->field_key ?? $this->field['field_key'];
419 + $field_id = isset( $this->field->id ) ? $this->field->id : $this->field['id'];
420 + $field_name = isset( $this->field->name ) ? $this->field->name : $this->field['name'];
421 + $field_key = isset( $this->field->field_key ) ? $this->field->field_key : $this->field['field_key'];
467 422 $sub_fields = $this->get_processed_sub_fields();
468 -
469 423 foreach ( $sub_fields as $name => $sub_field ) {
470 424 $headings[ $field_id . '_' . $name ] = $field_name . ' (' . $field_key . ') - ' . $sub_field['label'];
471 425 }
472 426
@@ -473,8 +427,9 @@
473 427 return $headings;
474 428 }
475 429
476 430 /**
431 + *
477 432 * Get a list of all field settings that should be translated
478 433 * on a multilingual site.
479 434 *
480 435 * @since 3.06.01
@@ -511,35 +466,6 @@
511 466 return array(
512 467 'class' => 'frm_combo_inputs_container',
513 468 'id' => 'frm_combo_inputs_container_' . $this->field_id,
514 469 );
515 - }
516 -
517 - /**
518 - * Gets subfield input attributes.
519 - *
520 - * @since 6.26
521 - *
522 - * @param array $sub_field Subfield data.
523 - * @param array $args Field output args. See {@see FrmFieldCombo::load_field_output()}.
524 - *
525 - * @return array
526 - */
527 - protected function get_sub_field_input_attrs( $sub_field, $args ) {
528 - $attrs = array(
529 - 'type' => $sub_field['type'],
530 - 'id' => $args['html_id'] . '_' . $sub_field['name'],
531 - 'value' => '',
532 - );
533 -
534 - if ( ! empty( $args['field']['value'][ $sub_field['name'] ] ) ) {
535 - $attrs['value'] = $args['field']['value'][ $sub_field['name'] ];
536 - $attrs['data-frmval'] = $args['field']['value'][ $sub_field['name'] ];
537 - }
538 -
539 - if ( empty( $args['remove_names'] ) ) {
540 - $attrs['name'] = $args['field_name'] . '[' . $sub_field['name'] . ']';
541 - }
542 -
543 - return $attrs;
544 470 }
545 471 }