PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
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/FrmFieldFormHtml.php +18 -101 6.5.33.06.06 View file →
@@ -1,9 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 -
6 2 /**
7 3 * @since 3.0
8 4 */
9 5
@@ -13,9 +9,9 @@
13 9
14 10 private $html_id;
15 11
16 12 /**
17 - * @var FrmFieldType
13 + * @var FrmFieldType
18 14 */
19 15 private $field_obj;
20 16
21 17 private $field_id;
@@ -86,10 +82,10 @@
86 82 * @param array $atts
87 83 */
88 84 private function set_pass_args( $atts ) {
89 85 $this->pass_args = $atts;
86 + $exclude = array( 'field_obj', 'html' );
90 87
91 - $exclude = array( 'field_obj', 'html' );
92 88 foreach ( $exclude as $ex ) {
93 89 if ( isset( $atts[ $ex ] ) ) {
94 90 unset( $this->pass_args[ $ex ] );
95 91 }
@@ -136,10 +132,8 @@
136 132 $this->replace_entry_key();
137 133 $this->replace_form_shortcodes();
138 134 $this->process_wp_shortcodes();
139 135 $this->maybe_replace_description_shortcode( true );
140 -
141 - $this->add_multiple_input_attributes();
142 136 }
143 137
144 138 /**
145 139 * @since 3.0
@@ -154,9 +148,9 @@
154 148 //replace [key]
155 149 $this->html = str_replace( '[key]', $this->field_obj->get_field_column( 'field_key' ), $this->html );
156 150
157 151 //replace [field_name]
158 - $this->html = str_replace( '[field_name]', FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'name' ) ), $this->html );
152 + $this->html = str_replace( '[field_name]', $this->field_obj->get_field_column( 'name' ), $this->html );
159 153 }
160 154
161 155 /**
162 156 * @since 3.0
@@ -172,9 +166,9 @@
172 166 *
173 167 * @since 3.0
174 168 */
175 169 private function maybe_replace_description_shortcode( $wp_processed = false ) {
176 - $is_html = 'html' === $this->field_obj->get_field_column( 'type' );
170 + $is_html = 'html' === $this->field_obj->get_field_column( 'type' );
177 171 $should_replace = ( $is_html && $wp_processed ) || ( ! $is_html && ! $wp_processed );
178 172 if ( $should_replace ) {
179 173 $this->replace_description_shortcode();
180 174 }
@@ -184,9 +178,9 @@
184 178 * @since 3.0
185 179 */
186 180 private function replace_description_shortcode() {
187 181 $this->maybe_add_description_id();
188 - $description = FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'description' ) );
182 + $description = $this->field_obj->get_field_column( 'description' );
189 183 FrmShortcodeHelper::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $this->html );
190 184 }
191 185
192 186 /**
@@ -231,42 +225,12 @@
231 225 */
232 226 private function replace_error_shortcode() {
233 227 $this->maybe_add_error_id();
234 228 $error = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? $this->pass_args['errors'][ 'field' . $this->field_id ] : false;
235 -
236 - if ( ! empty( $error ) && false === strpos( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) {
237 - $error_body = self::get_error_body( $this->html );
238 - if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) {
239 - $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 );
240 - $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html );
241 - }
242 - }
243 -
244 229 FrmShortcodeHelper::remove_inline_conditions( ! empty( $error ), 'error', $error, $this->html );
245 230 }
246 231
247 232 /**
248 - * Pull the HTML between [if error] and [/if error] shortcodes.
249 - *
250 - * @param string $html
251 - * @return string|false
252 - */
253 - private static function get_error_body( $html ) {
254 - $start = strpos( $html, '[if error]' );
255 - if ( false === $start ) {
256 - return false;
257 - }
258 -
259 - $end = strpos( $html, '[/if error]', $start );
260 - if ( false === $end ) {
261 - return false;
262 - }
263 -
264 - $error_body = substr( $html, $start + 10, $end - $start - 10 );
265 - return $error_body;
266 - }
267 -
268 - /**
269 233 * Add an ID to the error message for aria-describedby.
270 234 * This ID was added to the HTML in v3.06.02.
271 235 *
272 236 * @since 3.06.02
@@ -285,9 +249,9 @@
285 249 * @since 3.0
286 250 */
287 251 private function replace_required_class() {
288 252 $required_class = FrmField::is_required( $this->field_obj->get_field() ) ? ' frm_required_field' : '';
289 - $this->html = str_replace( '[required_class]', $required_class, $this->html );
253 + $this->html = str_replace( '[required_class]', $required_class, $this->html );
290 254 }
291 255
292 256 /**
293 257 * @since 3.0
@@ -352,9 +316,9 @@
352 316 preg_match_all( "/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $this->html, $shortcodes, PREG_PATTERN_ORDER );
353 317
354 318 foreach ( $shortcodes[0] as $short_key => $tag ) {
355 319 $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
356 - $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
320 + $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
357 321
358 322 $replace_with = '';
359 323
360 324 if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) {
@@ -373,9 +337,8 @@
373 337 * @return string
374 338 */
375 339 private function replace_input_shortcode( $shortcode_atts ) {
376 340 $shortcode_atts = $this->prepare_input_shortcode_atts( $shortcode_atts );
377 -
378 341 return $this->field_obj->include_front_field_input( $this->pass_args, $shortcode_atts );
379 342 }
380 343
381 344 /**
@@ -384,9 +347,9 @@
384 347 * @return array
385 348 */
386 349 private function prepare_input_shortcode_atts( $shortcode_atts ) {
387 350 if ( isset( $shortcode_atts['opt'] ) ) {
388 - $shortcode_atts['opt'] --;
351 + $shortcode_atts['opt']--;
389 352 }
390 353
391 354 $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : '';
392 355 $this->field_obj->set_field_column( 'input_class', $field_class );
@@ -394,9 +357,11 @@
394 357 if ( isset( $shortcode_atts['class'] ) ) {
395 358 unset( $shortcode_atts['class'] );
396 359 }
397 360
398 - $shortcode_atts['aria-invalid'] = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false';
361 + if ( isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) {
362 + $shortcode_atts['aria-invalid'] = 'true';
363 + }
399 364
400 365 $this->field_obj->set_field_column( 'shortcodes', $shortcode_atts );
401 366
402 367 return $shortcode_atts;
@@ -409,9 +374,12 @@
409 374 * @since 3.0
410 375 */
411 376 private function add_class_to_label() {
412 377 $label_class = $this->field_obj->get_label_class();
413 - $this->html = str_replace( '[label_position]', $label_class, $this->html );
378 + $this->html = str_replace( '[label_position]', $label_class, $this->html );
379 + if ( $this->field_obj->get_field_column( 'label' ) == 'inside' && $this->field_obj->get_field_column( 'value' ) != '' ) {
380 + $this->html = str_replace( 'frm_primary_label', 'frm_primary_label frm_visible', $this->html );
381 + }
414 382 }
415 383
416 384 /**
417 385 * Replace [entry_key]
@@ -418,9 +386,9 @@
418 386 *
419 387 * @since 3.0
420 388 */
421 389 private function replace_entry_key() {
422 - $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
390 + $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
423 391 $this->html = str_replace( '[entry_key]', $entry_key, $this->html );
424 392 }
425 393
426 394 /**
@@ -437,8 +405,9 @@
437 405 }
438 406 $this->html = str_replace( '[error_class]', $classes, $this->html );
439 407 }
440 408
409 +
441 410 /**
442 411 * Get the classes for a field div
443 412 *
444 413 * @since 3.0
@@ -451,15 +420,9 @@
451 420
452 421 // Add label position class
453 422 $settings = $this->field_obj->display_field_settings();
454 423 if ( isset( $settings['label_position'] ) && $settings['label_position'] ) {
455 - $label_position = $this->field_obj->get_field_column( 'label' );
456 - $classes .= ' frm_' . $label_position . '_container';
457 -
458 - // Add class if field has value, to be used for floating label styling.
459 - if ( 'inside' === $label_position && $this->field_obj->get_field_column( 'value' ) ) {
460 - $classes .= ' frm_label_float_top';
461 - }
424 + $classes .= ' frm_' . $this->field_obj->get_field_column( 'label' ) . '_container';
462 425 }
463 426
464 427 // Add CSS layout classes
465 428 $extra_classes = $this->field_obj->get_field_column( 'classes' );
@@ -484,52 +447,6 @@
484 447 private function process_wp_shortcodes() {
485 448 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
486 449 $this->html = do_shortcode( $this->html );
487 450 }
488 - }
489 -
490 - /**
491 - * Adds multiple input attributes.
492 - *
493 - * @since 6.4.1
494 - * @return void
495 - */
496 - private function add_multiple_input_attributes() {
497 - $field_type = $this->field_obj->get_field_column( 'type' );
498 -
499 - // Check if the field type is one of the following.
500 - if ( ! in_array( $field_type, array( 'radio', 'checkbox', 'data', 'product', 'scale' ), true ) ) {
501 - return;
502 - }
503 -
504 - $field = (array) $this->field_obj->get_field();
505 - $attributes = array();
506 - $is_radio = 'radio' === $field_type || 'scale' === $field_type;
507 - $type_requires_aria_required = true;
508 -
509 - // Check if the field type is 'data' or 'product'.
510 - if ( in_array( $field_type, array( 'data', 'product' ), true ) ) {
511 - $data_type = FrmField::get_option( $field, 'data_type' );
512 - // Check if the data type isn't 'radio' or 'checkbox'.
513 - if ( 'radio' !== $data_type && 'checkbox' !== $data_type ) {
514 - // If data type aren't 'radio' or 'checkbox', doesn't need to add 'aria-required' to multiple input container.
515 - $type_requires_aria_required = false;
516 - }
517 - // Check if data type is 'radio'
518 - if ( 'radio' === $data_type ) {
519 - $is_radio = true;
520 - }
521 - }
522 -
523 - // Add 'role' attribute to the field.
524 - $attributes['role'] = $is_radio ? 'radiogroup' : 'group';
525 -
526 - // Add 'aria-required' attribute to the field if required.
527 - if ( $type_requires_aria_required && '1' === $field['required'] ) {
528 - $attributes['aria-required'] = 'true';
529 - }
530 -
531 - // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string.
532 - $html_attributes = FrmAppHelper::array_to_html_params( $attributes );
533 - $this->html = str_replace( ' role="group"', $html_attributes, $this->html );
534 451 }
535 452 }