| @@ -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 | /** |
| @@ -303,18 +314,16 @@ | ||
| 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 | 329 | if ( ! isset( $response['success'] ) || $response['success'] ) { |