PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2
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 +25 -86 6.336.2 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
@@ -55,9 +53,9 @@
55 53 protected function register_sub_fields( array $sub_fields ) {
56 54 $defaults = $this->get_default_sub_field();
57 55
58 56 foreach ( $sub_fields as $name => $sub_field ) {
59 - if ( ! $sub_field ) {
57 + if ( empty( $sub_field ) ) {
60 58 continue;
61 59 }
62 60
63 61 if ( is_array( $sub_field ) ) {
@@ -75,24 +73,8 @@
75 73 ),
76 74 $defaults
77 75 );
78 76 }
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 77 }
96 78 }
97 79
98 80 /**
@@ -130,10 +112,9 @@
130 112 continue;
131 113 }
132 114
133 115 foreach ( $sub_field['options'] as $option ) {
134 - if ( 'default_value' === $option ) {
135 - // We parse default value from field column.
116 + if ( 'default_value' === $option ) { // We parse default value from field column.
136 117 continue;
137 118 }
138 119
139 120 if ( is_string( $option ) ) {
@@ -164,9 +145,8 @@
164 145
165 146 foreach ( $this->sub_fields as $name => $sub_field ) {
166 147 $sub_field['name'] = $name;
167 148 $wrapper_classes = 'frm_grid_container frm_sub_field_options frm_sub_field_options-' . $sub_field['name'];
168 -
169 149 if ( ! isset( $processed_sub_fields[ $name ] ) ) {
170 150 // Options for this subfield should be hidden.
171 151 $wrapper_classes .= ' frm_hidden';
172 152 }
@@ -201,10 +181,9 @@
201 181
202 182 return $default_value;
203 183 }
204 184
205 - // We store default value as JSON string in db.
206 - return json_decode( $default_value, true );
185 + return json_decode( $default_value, true ); // We store default value as JSON string in db.
207 186 }
208 187
209 188 /**
210 189 * Gets labels for built-in options of fields or sub fields.
@@ -224,16 +203,17 @@
224 203 *
225 204 * @return array
226 205 */
227 206 protected function field_settings_for_type() {
228 - return array(
207 + $settings = array(
229 208 'description' => false,
230 209 'default' => false,
231 - // Don't use the regular placeholder option.
232 - 'clear_on_focus' => false,
210 + 'clear_on_focus' => false, // Don't use the regular placeholder option.
233 211 'logic' => true,
234 212 'visibility' => true,
235 213 );
214 +
215 + return $settings;
236 216 }
237 217
238 218 /**
239 219 * Shows field on the form builder.
@@ -267,9 +247,8 @@
267 247 * Shows field in the frontend.
268 248 *
269 249 * @param array $args Arguments.
270 250 * @param array $shortcode_atts Shortcode attributes.
271 - *
272 251 * @return string
273 252 */
274 253 public function front_field_input( $args, $shortcode_atts ) {
275 254 $field = (array) $this->field;
@@ -274,9 +253,8 @@
274 253 public function front_field_input( $args, $shortcode_atts ) {
275 254 $field = (array) $this->field;
276 255
277 256 $field['default_value'] = $this->get_default_value();
278 -
279 257 if ( empty( $field['value'] ) ) {
280 258 $field['value'] = $field['default_value'];
281 259 }
282 260
@@ -284,10 +262,11 @@
284 262 $args['shortcode_atts'] = $shortcode_atts;
285 263
286 264 ob_start();
287 265 $this->load_field_output( $args );
266 + $input_html = ob_get_clean();
288 267
289 - return ob_get_clean();
268 + return $input_html;
290 269 }
291 270
292 271 /**
293 272 * Loads field output.
@@ -376,9 +355,8 @@
376 355
377 356 // Placeholder.
378 357 if ( in_array( 'placeholder', $sub_field['options'], true ) ) {
379 358 $placeholders = FrmField::get_option( $field, 'placeholder' );
380 -
381 359 if ( ! empty( $placeholders[ $sub_field['name'] ] ) ) {
382 360 $field['placeholder'] = $placeholders[ $sub_field['name'] ];
383 361 }
384 362 }
@@ -383,10 +361,9 @@
383 361 }
384 362 }
385 363
386 364 // Add optional class.
387 - $classes = $sub_field['classes'] ?? '';
388 -
365 + $classes = isset( $sub_field['classes'] ) ? $sub_field['classes'] : '';
389 366 if ( is_array( $classes ) ) {
390 367 $classes = implode( ' ', $classes );
391 368 }
392 369
@@ -397,25 +374,18 @@
397 374 if ( $classes ) {
398 375 $field['input_class'] = esc_attr( $classes );
399 376 }
400 377
401 - // Fake it to avoid printing frm-val attribute.
402 - $field['default_value'] = '';
378 + $field['default_value'] = ''; // fake it to avoid printing frm-val attribute.
403 379
404 - if ( ! empty( $sub_field['name'] ) ) {
405 - $field['subfield_name'] = $sub_field['name'];
406 - }
407 -
408 380 do_action( 'frm_field_input_html', $field );
409 381
410 382 // Print custom attributes.
411 - if ( empty( $sub_field['atts'] ) || ! is_array( $sub_field['atts'] ) ) {
412 - return;
383 + if ( ! empty( $sub_field['atts'] ) && is_array( $sub_field['atts'] ) ) {
384 + foreach ( $sub_field['atts'] as $att_name => $att_value ) {
385 + echo esc_attr( trim( $att_name ) ) . '="' . esc_attr( trim( $att_value ) ) . '" ';
386 + }
413 387 }
414 -
415 - foreach ( $sub_field['atts'] as $att_name => $att_value ) {
416 - echo esc_attr( trim( $att_name ) ) . '="' . esc_attr( trim( $att_value ) ) . '" ';
417 - }
418 388 }
419 389
420 390 /**
421 391 * Validate field.
@@ -420,13 +390,12 @@
420 390 /**
421 391 * Validate field.
422 392 *
423 393 * @param array $args Arguments. Includes `errors`, `value`.
424 - *
425 394 * @return array Errors array.
426 395 */
427 396 public function validate( $args ) {
428 - $errors = $args['errors'] ?? array();
397 + $errors = isset( $args['errors'] ) ? $args['errors'] : array();
429 398
430 399 if ( ! $this->field->required ) {
431 400 return $errors;
432 401 }
@@ -438,19 +407,18 @@
438 407 if ( class_exists( 'FrmProFieldsHelper' ) && ! FrmProFieldsHelper::is_field_visible_to_user( $this->field ) ) {
439 408 return $errors;
440 409 }
441 410
442 - $blank_msg = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
411 + $blank_msg = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
412 +
443 413 $sub_fields = $this->get_processed_sub_fields();
444 414
445 415 // Validate not empty.
446 416 foreach ( $sub_fields as $name => $sub_field ) {
447 - if ( ! empty( $sub_field['optional'] ) || ! empty( $args['value'][ $name ] ) ) {
448 - continue;
417 + if ( empty( $sub_field['optional'] ) && empty( $args['value'][ $name ] ) ) {
418 + $errors[ 'field' . $args['id'] . '-' . $name ] = '';
419 + $errors[ 'field' . $args['id'] ] = $blank_msg;
449 420 }
450 -
451 - $errors[ 'field' . $args['id'] . '-' . $name ] = '';
452 - $errors[ 'field' . $args['id'] ] = $blank_msg;
453 421 }
454 422
455 423 return $errors;
456 424 }
@@ -461,13 +429,12 @@
461 429 * @return array
462 430 */
463 431 public function get_export_headings() {
464 432 $headings = array();
465 - $field_id = $this->field->id ?? $this->field['id'];
466 - $field_name = $this->field->name ?? $this->field['name'];
467 - $field_key = $this->field->field_key ?? $this->field['field_key'];
433 + $field_id = isset( $this->field->id ) ? $this->field->id : $this->field['id'];
434 + $field_name = isset( $this->field->name ) ? $this->field->name : $this->field['name'];
435 + $field_key = isset( $this->field->field_key ) ? $this->field->field_key : $this->field['field_key'];
468 436 $sub_fields = $this->get_processed_sub_fields();
469 -
470 437 foreach ( $sub_fields as $name => $sub_field ) {
471 438 $headings[ $field_id . '_' . $name ] = $field_name . ' (' . $field_key . ') - ' . $sub_field['label'];
472 439 }
473 440
@@ -474,8 +441,9 @@
474 441 return $headings;
475 442 }
476 443
477 444 /**
445 + *
478 446 * Get a list of all field settings that should be translated
479 447 * on a multilingual site.
480 448 *
481 449 * @since 3.06.01
@@ -512,35 +480,6 @@
512 480 return array(
513 481 'class' => 'frm_combo_inputs_container',
514 482 'id' => 'frm_combo_inputs_container_' . $this->field_id,
515 483 );
516 - }
517 -
518 - /**
519 - * Gets subfield input attributes.
520 - *
521 - * @since 6.26
522 - *
523 - * @param array $sub_field Subfield data.
524 - * @param array $args Field output args. See {@see FrmFieldCombo::load_field_output()}.
525 - *
526 - * @return array
527 - */
528 - protected function get_sub_field_input_attrs( $sub_field, $args ) {
529 - $attrs = array(
530 - 'type' => $sub_field['type'],
531 - 'id' => $args['html_id'] . '_' . $sub_field['name'],
532 - 'value' => '',
533 - );
534 -
535 - if ( ! empty( $args['field']['value'][ $sub_field['name'] ] ) ) {
536 - $attrs['value'] = $args['field']['value'][ $sub_field['name'] ];
537 - $attrs['data-frmval'] = $args['field']['value'][ $sub_field['name'] ];
538 - }
539 -
540 - if ( empty( $args['remove_names'] ) ) {
541 - $attrs['name'] = $args['field_name'] . '[' . $sub_field['name'] . ']';
542 - }
543 -
544 - return $attrs;
545 484 }
546 485 }