Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions classes/models/fields/FrmFieldCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,29 @@ protected function extra_field_opts() {
}

/**
* Replace the "for" attribute for captcha field so it matches the response ID.
* Modify the captcha field label so it is not orphaned.
*
* The label is omitted when the label position is set to "none".
* When the label is visible it is rendered as a <span> instead of a <label>,
* since the captcha response input is inside an iframe and cannot be referenced.
*
* @param array $args
* @param string $html
*
* @return string
*/
protected function before_replace_html_shortcodes( $args, $html ) {
$settings = FrmCaptchaFactory::get_settings_object();
return str_replace( ' for="field_[key]"', ' for="' . esc_attr( $settings->token_field ) . '"', $html );
if ( 'none' === FrmField::get_option( $this->field, 'label' ) ) {
// Fully strip the label for a CAPTCHA if it is set to hidden.
return preg_replace( '~\s*<label\b[^>]*for="field_\[key\]"[^>]*>.*?</label>\s*~s', '', $html );
}

// Convert a CAPTCHA label to a span to prevent an orphaned label issue in WAVE.
return preg_replace(
'~<label\b([^>]*?)\s*for="field_\[key\]"([^>]*?)>(.*?)</label>~s',
'<span$1$2>$3</span>',
$html
);
}

/**
Expand Down
Loading