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 +34 -105 6.345.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,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,27 +334,24 @@
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'];
342 + $atts = array();
376 343
377 344 // Placeholder.
378 345 if ( in_array( 'placeholder', $sub_field['options'], true ) ) {
379 346 $placeholders = FrmField::get_option( $field, 'placeholder' );
380 -
381 347 if ( ! empty( $placeholders[ $sub_field['name'] ] ) ) {
382 - $field['placeholder'] = $placeholders[ $sub_field['name'] ];
348 + $atts[] = 'placeholder="' . esc_attr( $placeholders[ $sub_field['name'] ] ) . '"';
383 349 }
384 350 }
385 351
386 352 // Add optional class.
387 - $classes = $sub_field['classes'] ?? '';
388 -
353 + $classes = isset( $sub_field['classes'] ) ? $sub_field['classes'] : '';
389 354 if ( is_array( $classes ) ) {
390 355 $classes = implode( ' ', $classes );
391 356 }
392 357
@@ -394,28 +359,19 @@
394 359 $classes .= ' frm_optional';
395 360 }
396 361
397 362 if ( $classes ) {
398 - $field['input_class'] = esc_attr( $classes );
363 + $atts[] = 'class="' . esc_attr( $classes ) . '"';
399 364 }
400 365
401 - // Fake it to avoid printing frm-val attribute.
402 - $field['default_value'] = '';
403 -
404 - if ( ! empty( $sub_field['name'] ) ) {
405 - $field['subfield_name'] = $sub_field['name'];
406 - }
407 -
408 - do_action( 'frm_field_input_html', $field );
409 -
410 366 // Print custom attributes.
411 - if ( empty( $sub_field['atts'] ) || ! is_array( $sub_field['atts'] ) ) {
412 - return;
367 + if ( ! empty( $sub_field['atts'] ) && is_array( $sub_field['atts'] ) ) {
368 + foreach ( $sub_field['atts'] as $att_name => $att_value ) {
369 + $atts[] = esc_attr( trim( $att_name ) ) . '="' . esc_attr( trim( $att_value ) ) . '"';
370 + }
413 371 }
414 372
415 - foreach ( $sub_field['atts'] as $att_name => $att_value ) {
416 - echo esc_attr( trim( $att_name ) ) . '="' . esc_attr( trim( $att_value ) ) . '" ';
417 - }
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 }
@@ -434,19 +389,22 @@
434 389 if ( class_exists( 'FrmProEntryMeta' ) && FrmProEntryMeta::skip_required_validation( $this->field ) ) {
435 390 return $errors;
436 391 }
437 392
438 - $blank_msg = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
393 + if ( class_exists( 'FrmProFieldsHelper' ) && ! FrmProFieldsHelper::is_field_visible_to_user( $this->field ) ) {
394 + return $errors;
395 + }
396 +
397 + $blank_msg = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
398 +
439 399 $sub_fields = $this->get_processed_sub_fields();
440 400
441 401 // Validate not empty.
442 402 foreach ( $sub_fields as $name => $sub_field ) {
443 - if ( ! empty( $sub_field['optional'] ) || ! empty( $args['value'][ $name ] ) ) {
444 - continue;
403 + if ( empty( $sub_field['optional'] ) && empty( $args['value'][ $name ] ) ) {
404 + $errors[ 'field' . $args['id'] . '-' . $name ] = '';
405 + $errors[ 'field' . $args['id'] ] = $blank_msg;
445 406 }
446 -
447 - $errors[ 'field' . $args['id'] . '-' . $name ] = '';
448 - $errors[ 'field' . $args['id'] ] = $blank_msg;
449 407 }
450 408
451 409 return $errors;
452 410 }
@@ -457,15 +415,14 @@
457 415 * @return array
458 416 */
459 417 public function get_export_headings() {
460 418 $headings = array();
461 - $field_id = is_object( $this->field ) ? $this->field->id : $this->field['id'];
462 - $field_name = is_object( $this->field ) ? $this->field->name : $this->field['name'];
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'];
463 422 $sub_fields = $this->get_processed_sub_fields();
464 -
465 - // Include sub-field headings.
466 423 foreach ( $sub_fields as $name => $sub_field ) {
467 - $headings[ $field_id . '_' . $name ] = $field_name . ' - ' . $sub_field['label'];
424 + $headings[ $field_id . '_' . $name ] = $field_name . ' (' . $field_key . ') - ' . $sub_field['label'];
468 425 }
469 426
470 427 return $headings;
471 428 }
@@ -470,8 +427,9 @@
470 427 return $headings;
471 428 }
472 429
473 430 /**
431 + *
474 432 * Get a list of all field settings that should be translated
475 433 * on a multilingual site.
476 434 *
477 435 * @since 3.06.01
@@ -503,40 +461,11 @@
503 461 * Gets inputs container attributes.
504 462 *
505 463 * @return array
506 464 */
507 - public function get_inputs_container_attrs() {
465 + protected function get_inputs_container_attrs() {
508 466 return array(
509 467 'class' => 'frm_combo_inputs_container',
510 468 'id' => 'frm_combo_inputs_container_' . $this->field_id,
511 469 );
512 - }
513 -
514 - /**
515 - * Gets subfield input attributes.
516 - *
517 - * @since 6.26
518 - *
519 - * @param array $sub_field Subfield data.
520 - * @param array $args Field output args. See {@see FrmFieldCombo::load_field_output()}.
521 - *
522 - * @return array
523 - */
524 - protected function get_sub_field_input_attrs( $sub_field, $args ) {
525 - $attrs = array(
526 - 'type' => $sub_field['type'],
527 - 'id' => $args['html_id'] . '_' . $sub_field['name'],
528 - 'value' => '',
529 - );
530 -
531 - if ( ! empty( $args['field']['value'][ $sub_field['name'] ] ) ) {
532 - $attrs['value'] = $args['field']['value'][ $sub_field['name'] ];
533 - $attrs['data-frmval'] = $args['field']['value'][ $sub_field['name'] ];
534 - }
535 -
536 - if ( empty( $args['remove_names'] ) ) {
537 - $attrs['name'] = $args['field_name'] . '[' . $sub_field['name'] . ']';
538 - }
539 -
540 - return $attrs;
541 470 }
542 471 }