| @@ -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 |