PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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/FrmFieldCaptcha.php +35 -24 6.27 → trunk View file →
@@ -71,10 +71,14 @@
71 71 );
72 72 }
73 73
74 74 /**
75 - * Replace the "for" attribute for captcha field so it matches the response ID.
75 + * Modify the captcha field label so it is not orphaned.
76 76 *
77 + * The label is omitted when the label position is set to "none".
78 + * When the label is visible it is rendered as a <span> instead of a <label>,
79 + * since the captcha response input is inside an iframe and cannot be referenced.
80 + *
77 81 * @param array $args
78 82 * @param string $html
79 83 *
80 84 * @return string
@@ -79,10 +83,19 @@
79 83 *
80 84 * @return string
81 85 */
82 86 protected function before_replace_html_shortcodes( $args, $html ) {
83 - $settings = FrmCaptchaFactory::get_settings_object();
84 - return str_replace( ' for="field_[key]"', ' for="' . esc_attr( $settings->token_field ) . '"', $html );
87 + if ( 'none' === FrmField::get_option( $this->field, 'label' ) ) {
88 + // Fully strip the label for a CAPTCHA if it is set to hidden.
89 + return preg_replace( '~\s*<label\b[^>]*for="field_\[key\]"[^>]*>.*?</label>\s*~s', '', $html );
90 + }
91 +
92 + // Convert a CAPTCHA label to a span to prevent an orphaned label issue in WAVE.
93 + return preg_replace(
94 + '~<label\b([^>]*?)\s*for="field_\[key\]"([^>]*?)>(.*?)</label>~s',
95 + '<span$1$2>$3</span>',
96 + $html
97 + );
85 98 }
86 99
87 100 /**
88 101 * @param array $args
@@ -140,11 +153,9 @@
140 153 *
141 154 * @return void
142 155 */
143 156 protected function load_field_scripts( $args ) {
144 - $api_js_url = $this->api_url();
145 -
146 - wp_register_script( 'captcha-api', $api_js_url, array( 'formidable' ), '3', true );
157 + wp_register_script( 'captcha-api', $this->api_url(), array( 'formidable' ), '3', true );
147 158 wp_enqueue_script( 'captcha-api' );
148 159 }
149 160
150 161 /**
@@ -239,9 +250,9 @@
239 250 */
240 251 $api_js_url = apply_filters( 'frm_turnstile_js_url', $api_js_url );
241 252
242 253 // Prevent render=explicit from happening twice in case someone patched
243 - // the double rendering issue using the frm_turnstile_js_url hook.
254 + // The double rendering issue using the frm_turnstile_js_url hook.
244 255 return str_replace(
245 256 '&render=explicit&render=explicit',
246 257 '&render=explicit',
247 258 $api_js_url
@@ -303,32 +314,32 @@
303 314 if ( ! is_array( $response ) ) {
304 315 return $errors;
305 316 }
306 317
307 - if ( $frm_settings->active_captcha === 'recaptcha' ) {
308 - if ( 'v3' === $frm_settings->re_type && array_key_exists( 'score', $response ) ) {
309 - $threshold = floatval( $frm_settings->re_threshold );
310 - $score = floatval( $response['score'] );
318 + if ( $frm_settings->active_captcha === 'recaptcha' && 'v3' === $frm_settings->re_type && array_key_exists( 'score', $response ) ) {
319 + $threshold = floatval( $frm_settings->re_threshold );
320 + $score = floatval( $response['score'] );
311 321
312 - $this->set_score( $score );
322 + $this->set_score( $score );
313 323
314 - if ( $score < $threshold ) {
315 - $response['success'] = false;
316 - }
324 + if ( $score < $threshold ) {
325 + $response['success'] = false;
317 326 }
318 327 }
319 328
320 - if ( isset( $response['success'] ) && ! $response['success'] ) {
321 - // What happens when the CAPTCHA was entered incorrectly
322 - $invalid_message = FrmField::get_option( $this->field, 'invalid' );
329 + if ( ! isset( $response['success'] ) || $response['success'] ) {
330 + return $errors;
331 + }
323 332
324 - if ( $invalid_message === __( 'The reCAPTCHA was not entered correctly', 'formidable' ) ) {
325 - $invalid_message = '';
326 - }
333 + // What happens when the CAPTCHA was entered incorrectly
334 + $invalid_message = FrmField::get_option( $this->field, 'invalid' );
327 335
328 - $errors[ 'field' . $args['id'] ] = $invalid_message === '' ? $frm_settings->re_msg : $invalid_message;
336 + if ( $invalid_message === __( 'The reCAPTCHA was not entered correctly', 'formidable' ) ) {
337 + $invalid_message = '';
329 338 }
330 339
340 + $errors[ 'field' . $args['id'] ] = $invalid_message === '' ? $frm_settings->re_msg : $invalid_message;
341 +
331 342 return $errors;
332 343 }
333 344
334 345 /**
@@ -401,9 +412,9 @@
401 412 if ( FrmAppHelper::is_admin() || $is_hidden_field ) {
402 413 return false;
403 414 }
404 415
405 - // don't require the captcha if it shouldn't be shown
416 + // Don't require the captcha if it shouldn't be shown
406 417 return self::should_show_captcha();
407 418 }
408 419
409 420 /**
@@ -428,9 +439,9 @@
428 439 * @since 6.0
429 440 *
430 441 * @param array $values
431 442 *
432 - * @return array $values
443 + * @return array Values.
433 444 */
434 445 public static function update_field_name( $values ) {
435 446 if ( $values['type'] === 'captcha' ) {
436 447 $name = $values['name'];