Skip to content

Commit c0ac591

Browse files
authored
Merge pull request #1519 from brainstormforce/recaptcha-multiple-submit-markup-issue
Disable submit button attribute markup for custom buttons
2 parents 1190162 + 60b0e88 commit c0ac591

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

inc/fields/inlinebutton-markup.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ public function __construct( $attributes ) {
166166
* @return string|bool|void
167167
*/
168168
public function markup() {
169+
$container_hidden_class = 'g-recaptcha' === $this->captcha_security_type && ( 'v3-reCAPTCHA' === $this->recaptcha_version || 'v2-invisible' === $this->recaptcha_version ) ? 'srfm-display-none' : '';
169170
ob_start(); ?>
170171
<?php if ( ! $this->is_page_break ) { ?>
171172
<?php if ( $this->captcha_security_type && 'none' !== $this->captcha_security_type ) { ?>
172-
<div class="srfm-captcha-container <?php echo esc_attr( 'v3-reCAPTCHA' === $this->recaptcha_version || 'v2-invisible' === $this->recaptcha_version ? 'srfm-display-none' : '' ); ?>">
173+
<div class="srfm-captcha-container <?php echo esc_attr( $container_hidden_class ); ?>">
173174
<?php if ( 'g-recaptcha' === $this->captcha_security_type && 'v2-checkbox' === $this->recaptcha_version ) { ?>
174175
<?php echo "<div class='g-recaptcha' data-callback='onSuccess' data-error-callback='onGCaptchaV2CheckBoxError' recaptcha-type='" . esc_attr( $this->recaptcha_version ) . "' data-sitekey='" . esc_attr( strval( $this->google_captcha_site_key ) ) . "'></div>"; ?>
175176
<?php } ?>
@@ -228,8 +229,16 @@ public function markup() {
228229
}
229230
}
230231
$srfm_custom_button_classes = apply_filters( 'srfm_add_button_classes', [ 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? 'g-recaptcha ' : '', '1' === $this->btn_from_theme ? 'wp-block-button__link' : 'srfm-button srfm-submit-button srfm-btn-frontend srfm-custom-button' ], $this->form_id );
232+
233+
$button_style = $this->btn_from_theme ? '' : ' font-family: inherit; font-weight: var(--wp--custom--font-weight--medium); line-height: normal;';
234+
$button_style .= 'width:100%;';
235+
236+
$button_attributes = '';
237+
if ( 'g-recaptcha' === $this->captcha_security_type && ( 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ) ) {
238+
$button_attributes = 'recaptcha-type=' . $this->recaptcha_version . ' data-sitekey=' . $this->google_captcha_site_key . ' data-callback="recaptchaCallback"';
239+
}
231240
?>
232-
<button style="<?php echo $this->btn_from_theme ? '' : ' font-family: inherit; font-weight: var(--wp--custom--font-weight--medium); line-height: normal;'; ?>width:100%;" id="srfm-submit-btn" class="<?php echo esc_attr( Helper::join_strings( $srfm_custom_button_classes ) ); ?>" <?php echo 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? esc_attr( 'recaptcha-type=' . $this->recaptcha_version . ' data-sitekey=' . $this->google_captcha_site_key ) . ' data-callback="recaptchaCallback"' : ''; ?>>
241+
<button style="<?php echo esc_attr( $button_style ); ?>" id="srfm-submit-btn" class="<?php echo esc_attr( Helper::join_strings( $srfm_custom_button_classes ) ); ?>" <?php echo esc_attr( $button_attributes ); ?>>
233242
<div class="srfm-submit-wrap">
234243
<?php echo esc_html( $this->button_text ); ?>
235244
<div class="srfm-loader"></div>

inc/generate-form-markup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public static function get_form_markup( $id, $show_title_current_page = true, $s
507507
<div style="width: <?php echo esc_attr( $full ? '100%' : '' ); ?>; text-align: <?php echo esc_attr( $submit_button_alignment ); ?>" class="wp-block-button">
508508
<?php do_action( 'srfm_before_submit_button', $id ); ?>
509509
<button style="<?php echo esc_attr( $full ? 'width: 100%;' : '' ); ?>" id="srfm-submit-btn" class="<?php echo esc_attr( implode( ' ', array_filter( $srfm_button_classes ) ) ); ?>"
510-
<?php if ( 'v3-reCAPTCHA' === $recaptcha_version ) { ?>
510+
<?php if ( $should_show_submit_button && 'v3-reCAPTCHA' === $recaptcha_version ) { ?>
511511
data-callback="recaptchaCallback"
512512
data-error-callback="onGCaptchaV3Error"
513513
recaptcha-type="<?php echo esc_attr( $recaptcha_version ); ?>"

0 commit comments

Comments
 (0)