PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.1
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 -99 6.325.1 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,16 +46,14 @@
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
58 54 foreach ( $sub_fields as $name => $sub_field ) {
59 - if ( ! $sub_field ) {
55 + if ( empty( $sub_field ) ) {
60 56 continue;
61 57 }
62 58
63 59 if ( is_array( $sub_field ) ) {
@@ -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.
@@ -224,16 +198,17 @@
224 198 *
225 199 * @return array
226 200 */
227 201 protected function field_settings_for_type() {
228 - return array(
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 );
209 +
210 + return $settings;
236 211 }
237 212
238 213 /**
239 214 * Shows field on the form builder.
@@ -238,10 +213,8 @@
238 213 /**
239 214 * Shows field on the form builder.
240 215 *
241 216 * @param string $name Field name.
242 - *
243 - * @return void
244 217 */
245 218 public function show_on_form_builder( $name = '' ) {
246 219 $field = FrmFieldsHelper::setup_edit_vars( $this->field );
247 220
@@ -267,9 +240,8 @@
267 240 * Shows field in the frontend.
268 241 *
269 242 * @param array $args Arguments.
270 243 * @param array $shortcode_atts Shortcode attributes.
271 - *
272 244 * @return string
273 245 */
274 246 public function front_field_input( $args, $shortcode_atts ) {
275 247 $field = (array) $this->field;
@@ -274,9 +246,8 @@
274 246 public function front_field_input( $args, $shortcode_atts ) {
275 247 $field = (array) $this->field;
276 248
277 249 $field['default_value'] = $this->get_default_value();
278 -
279 250 if ( empty( $field['value'] ) ) {
280 251 $field['value'] = $field['default_value'];
281 252 }
282 253
@@ -284,10 +255,11 @@
284 255 $args['shortcode_atts'] = $shortcode_atts;
285 256
286 257 ob_start();
287 258 $this->load_field_output( $args );
259 + $input_html = ob_get_clean();
288 260
289 - return ob_get_clean();
261 + return $input_html;
290 262 }
291 263
292 264 /**
293 265 * Loads field output.
@@ -301,10 +273,8 @@
301 273 * @type array $shortcode_atts Shortcode attributes.
302 274 * @type array $errors Field errors.
303 275 * @type bool $remove_names Remove name attribute or not.
304 276 * }
305 - *
306 - * @return void
307 277 */
308 278 protected function load_field_output( $args ) {
309 279 if ( empty( $args['field'] ) ) {
310 280 return;
@@ -337,10 +307,8 @@
337 307 * @type array $shortcode_atts Shortcode attributes.
338 308 * @type array $errors Field errors.
339 309 * @type bool $remove_names Remove name attribute or not.
340 310 * }
341 - *
342 - * @return void
343 311 */
344 312 protected function process_args_for_field_output( &$args ) {
345 313 $args['field'] = (array) $args['field'];
346 314
@@ -366,10 +334,8 @@
366 334 /**
367 335 * Prints sub field input atts.
368 336 *
369 337 * @param array $args Arguments. Includes `field`, `sub_field`.
370 - *
371 - * @return void
372 338 */
373 339 protected function print_input_atts( $args ) {
374 340 $field = $args['field'];
375 341 $sub_field = $args['sub_field'];
@@ -376,9 +342,8 @@
376 342
377 343 // Placeholder.
378 344 if ( in_array( 'placeholder', $sub_field['options'], true ) ) {
379 345 $placeholders = FrmField::get_option( $field, 'placeholder' );
380 -
381 346 if ( ! empty( $placeholders[ $sub_field['name'] ] ) ) {
382 347 $field['placeholder'] = $placeholders[ $sub_field['name'] ];
383 348 }
384 349 }
@@ -383,10 +348,9 @@
383 348 }
384 349 }
385 350
386 351 // Add optional class.
387 - $classes = $sub_field['classes'] ?? '';
388 -
352 + $classes = isset( $sub_field['classes'] ) ? $sub_field['classes'] : '';
389 353 if ( is_array( $classes ) ) {
390 354 $classes = implode( ' ', $classes );
391 355 }
392 356
@@ -397,25 +361,18 @@
397 361 if ( $classes ) {
398 362 $field['input_class'] = esc_attr( $classes );
399 363 }
400 364
401 - // Fake it to avoid printing frm-val attribute.
402 - $field['default_value'] = '';
365 + $field['default_value'] = ''; // fake it to avoid printing frm-val attribute.
403 366
404 - if ( ! empty( $sub_field['name'] ) ) {
405 - $field['subfield_name'] = $sub_field['name'];
406 - }
407 -
408 367 do_action( 'frm_field_input_html', $field );
409 368
410 369 // Print custom attributes.
411 - if ( empty( $sub_field['atts'] ) || ! is_array( $sub_field['atts'] ) ) {
412 - return;
370 + if ( ! empty( $sub_field['atts'] ) && is_array( $sub_field['atts'] ) ) {
371 + foreach ( $sub_field['atts'] as $att_name => $att_value ) {
372 + echo esc_attr( trim( $att_name ) ) . '="' . esc_attr( trim( $att_value ) ) . '" ';
373 + }
413 374 }
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 375 }
419 376
420 377 /**
421 378 * Validate field.
@@ -420,13 +377,12 @@
420 377 /**
421 378 * Validate field.
422 379 *
423 380 * @param array $args Arguments. Includes `errors`, `value`.
424 - *
425 381 * @return array Errors array.
426 382 */
427 383 public function validate( $args ) {
428 - $errors = $args['errors'] ?? array();
384 + $errors = isset( $args['errors'] ) ? $args['errors'] : array();
429 385
430 386 if ( ! $this->field->required ) {
431 387 return $errors;
432 388 }
@@ -438,19 +394,18 @@
438 394 if ( class_exists( 'FrmProFieldsHelper' ) && ! FrmProFieldsHelper::is_field_visible_to_user( $this->field ) ) {
439 395 return $errors;
440 396 }
441 397
442 - $blank_msg = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
398 + $blank_msg = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
399 +
443 400 $sub_fields = $this->get_processed_sub_fields();
444 401
445 402 // Validate not empty.
446 403 foreach ( $sub_fields as $name => $sub_field ) {
447 - if ( ! empty( $sub_field['optional'] ) || ! empty( $args['value'][ $name ] ) ) {
448 - continue;
404 + if ( empty( $sub_field['optional'] ) && empty( $args['value'][ $name ] ) ) {
405 + $errors[ 'field' . $args['id'] . '-' . $name ] = '';
406 + $errors[ 'field' . $args['id'] ] = $blank_msg;
449 407 }
450 -
451 - $errors[ 'field' . $args['id'] . '-' . $name ] = '';
452 - $errors[ 'field' . $args['id'] ] = $blank_msg;
453 408 }
454 409
455 410 return $errors;
456 411 }
@@ -461,13 +416,12 @@
461 416 * @return array
462 417 */
463 418 public function get_export_headings() {
464 419 $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'];
420 + $field_id = isset( $this->field->id ) ? $this->field->id : $this->field['id'];
421 + $field_name = isset( $this->field->name ) ? $this->field->name : $this->field['name'];
422 + $field_key = isset( $this->field->field_key ) ? $this->field->field_key : $this->field['field_key'];
468 423 $sub_fields = $this->get_processed_sub_fields();
469 -
470 424 foreach ( $sub_fields as $name => $sub_field ) {
471 425 $headings[ $field_id . '_' . $name ] = $field_name . ' (' . $field_key . ') - ' . $sub_field['label'];
472 426 }
473 427
@@ -474,8 +428,9 @@
474 428 return $headings;
475 429 }
476 430
477 431 /**
432 + *
478 433 * Get a list of all field settings that should be translated
479 434 * on a multilingual site.
480 435 *
481 436 * @since 3.06.01
@@ -512,35 +467,6 @@
512 467 return array(
513 468 'class' => 'frm_combo_inputs_container',
514 469 'id' => 'frm_combo_inputs_container_' . $this->field_id,
515 470 );
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 471 }
546 472 }