PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +20 -78 6.32.1 → 6.13 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 ) ) {
@@ -79,24 +77,8 @@
79 77 }//end foreach
80 78 }
81 79
82 80 /**
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 - }
96 - }
97 -
98 - /**
99 81 * Gets default sub field.
100 82 *
101 83 * @return array
102 84 */
@@ -164,9 +146,8 @@
164 146
165 147 foreach ( $this->sub_fields as $name => $sub_field ) {
166 148 $sub_field['name'] = $name;
167 149 $wrapper_classes = 'frm_grid_container frm_sub_field_options frm_sub_field_options-' . $sub_field['name'];
168 -
169 150 if ( ! isset( $processed_sub_fields[ $name ] ) ) {
170 151 // Options for this subfield should be hidden.
171 152 $wrapper_classes .= ' frm_hidden';
172 153 }
@@ -224,9 +205,9 @@
224 205 *
225 206 * @return array
226 207 */
227 208 protected function field_settings_for_type() {
228 - return array(
209 + $settings = array(
229 210 'description' => false,
230 211 'default' => false,
231 212 // Don't use the regular placeholder option.
232 213 'clear_on_focus' => false,
@@ -232,8 +213,10 @@
232 213 'clear_on_focus' => false,
233 214 'logic' => true,
234 215 'visibility' => true,
235 216 );
217 +
218 + return $settings;
236 219 }
237 220
238 221 /**
239 222 * Shows field on the form builder.
@@ -267,9 +250,8 @@
267 250 * Shows field in the frontend.
268 251 *
269 252 * @param array $args Arguments.
270 253 * @param array $shortcode_atts Shortcode attributes.
271 - *
272 254 * @return string
273 255 */
274 256 public function front_field_input( $args, $shortcode_atts ) {
275 257 $field = (array) $this->field;
@@ -274,9 +256,8 @@
274 256 public function front_field_input( $args, $shortcode_atts ) {
275 257 $field = (array) $this->field;
276 258
277 259 $field['default_value'] = $this->get_default_value();
278 -
279 260 if ( empty( $field['value'] ) ) {
280 261 $field['value'] = $field['default_value'];
281 262 }
282 263
@@ -284,10 +265,11 @@
284 265 $args['shortcode_atts'] = $shortcode_atts;
285 266
286 267 ob_start();
287 268 $this->load_field_output( $args );
269 + $input_html = ob_get_clean();
288 270
289 - return ob_get_clean();
271 + return $input_html;
290 272 }
291 273
292 274 /**
293 275 * Loads field output.
@@ -376,9 +358,8 @@
376 358
377 359 // Placeholder.
378 360 if ( in_array( 'placeholder', $sub_field['options'], true ) ) {
379 361 $placeholders = FrmField::get_option( $field, 'placeholder' );
380 -
381 362 if ( ! empty( $placeholders[ $sub_field['name'] ] ) ) {
382 363 $field['placeholder'] = $placeholders[ $sub_field['name'] ];
383 364 }
384 365 }
@@ -383,10 +364,9 @@
383 364 }
384 365 }
385 366
386 367 // Add optional class.
387 - $classes = $sub_field['classes'] ?? '';
388 -
368 + $classes = isset( $sub_field['classes'] ) ? $sub_field['classes'] : '';
389 369 if ( is_array( $classes ) ) {
390 370 $classes = implode( ' ', $classes );
391 371 }
392 372
@@ -400,22 +380,16 @@
400 380
401 381 // Fake it to avoid printing frm-val attribute.
402 382 $field['default_value'] = '';
403 383
404 - if ( ! empty( $sub_field['name'] ) ) {
405 - $field['subfield_name'] = $sub_field['name'];
406 - }
407 -
408 384 do_action( 'frm_field_input_html', $field );
409 385
410 386 // Print custom attributes.
411 - if ( empty( $sub_field['atts'] ) || ! is_array( $sub_field['atts'] ) ) {
412 - return;
387 + if ( ! empty( $sub_field['atts'] ) && is_array( $sub_field['atts'] ) ) {
388 + foreach ( $sub_field['atts'] as $att_name => $att_value ) {
389 + echo esc_attr( trim( $att_name ) ) . '="' . esc_attr( trim( $att_value ) ) . '" ';
390 + }
413 391 }
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 392 }
419 393
420 394 /**
421 395 * Validate field.
@@ -420,13 +394,12 @@
420 394 /**
421 395 * Validate field.
422 396 *
423 397 * @param array $args Arguments. Includes `errors`, `value`.
424 - *
425 398 * @return array Errors array.
426 399 */
427 400 public function validate( $args ) {
428 - $errors = $args['errors'] ?? array();
401 + $errors = isset( $args['errors'] ) ? $args['errors'] : array();
429 402
430 403 if ( ! $this->field->required ) {
431 404 return $errors;
432 405 }
@@ -438,19 +411,18 @@
438 411 if ( class_exists( 'FrmProFieldsHelper' ) && ! FrmProFieldsHelper::is_field_visible_to_user( $this->field ) ) {
439 412 return $errors;
440 413 }
441 414
442 - $blank_msg = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
415 + $blank_msg = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
416 +
443 417 $sub_fields = $this->get_processed_sub_fields();
444 418
445 419 // Validate not empty.
446 420 foreach ( $sub_fields as $name => $sub_field ) {
447 - if ( ! empty( $sub_field['optional'] ) || ! empty( $args['value'][ $name ] ) ) {
448 - continue;
421 + if ( empty( $sub_field['optional'] ) && empty( $args['value'][ $name ] ) ) {
422 + $errors[ 'field' . $args['id'] . '-' . $name ] = '';
423 + $errors[ 'field' . $args['id'] ] = $blank_msg;
449 424 }
450 -
451 - $errors[ 'field' . $args['id'] . '-' . $name ] = '';
452 - $errors[ 'field' . $args['id'] ] = $blank_msg;
453 425 }
454 426
455 427 return $errors;
456 428 }
@@ -461,13 +433,12 @@
461 433 * @return array
462 434 */
463 435 public function get_export_headings() {
464 436 $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'];
437 + $field_id = isset( $this->field->id ) ? $this->field->id : $this->field['id'];
438 + $field_name = isset( $this->field->name ) ? $this->field->name : $this->field['name'];
439 + $field_key = isset( $this->field->field_key ) ? $this->field->field_key : $this->field['field_key'];
468 440 $sub_fields = $this->get_processed_sub_fields();
469 -
470 441 foreach ( $sub_fields as $name => $sub_field ) {
471 442 $headings[ $field_id . '_' . $name ] = $field_name . ' (' . $field_key . ') - ' . $sub_field['label'];
472 443 }
473 444
@@ -512,35 +483,6 @@
512 483 return array(
513 484 'class' => 'frm_combo_inputs_container',
514 485 'id' => 'frm_combo_inputs_container_' . $this->field_id,
515 486 );
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 487 }
546 488 }