Adding ReCaptcha to theme contact form
-
After reading Custom Form instructions outlined on https://support.bestwebsoft.com/hc/en-us/articles/202352499, I entered the plugin output code onto my theme contact form.
ReCaptcha is displayed on the form page, but the validation does not kick in.
The theme contact form has its own form validation (contact-form-handlers.php) – I added the entered data checking code onto the file, but it is still not validating the entry.
Below is the original validation function from the file:
/*
* Verify Recaptcha
*/
$show_reCAPTCHA = get_option( ‘theme_show_reCAPTCHA’ );
$reCAPTCHA_public_key = get_option( ‘theme_recaptcha_public_key’ );
$reCAPTCHA_private_key = get_option( ‘theme_recaptcha_private_key’ );if ( ! empty( $reCAPTCHA_public_key ) && ! empty( $reCAPTCHA_private_key ) && $show_reCAPTCHA == ‘true’ ) {
/* Include recaptcha library */
require_once( get_template_directory() . ‘/recaptcha/recaptchalib.php’ );
$resp = recaptcha_check_answer( $reCAPTCHA_private_key,
$_SERVER[ “REMOTE_ADDR” ],
$_POST[ “recaptcha_challenge_field” ],
$_POST[ “recaptcha_response_field” ] );if ( ! $resp->is_valid ) {
/* What happens when the CAPTCHA was entered incorrectly */
echo json_encode( array(
‘success’ => false,
‘message’ => __( ‘The reCAPTCHA is not correct. Please try again.’, ‘framework’ )
) );
die;
}
}
The topic ‘Adding ReCaptcha to theme contact form’ is closed to new replies.