{"id":10552383,"date":"2018-08-02T19:00:38","date_gmt":"2018-08-02T19:00:38","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/adding-recaptcha-to-theme-contact-form\/"},"modified":"2018-08-02T19:00:38","modified_gmt":"2018-08-02T19:00:38","slug":"adding-recaptcha-to-theme-contact-form","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/adding-recaptcha-to-theme-contact-form\/","title":{"rendered":"Adding ReCaptcha to theme contact form"},"content":{"rendered":"<p>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. <\/p>\n<p>ReCaptcha is displayed on the form page, but the validation does not kick in.<\/p>\n<p>The theme contact form has its own form validation (contact-form-handlers.php) &#8211; I added the entered data checking code onto the file, but it is still not validating the entry.<\/p>\n<p>Below is the original validation function from the file:<\/p>\n<p>\/*<br \/>\n\t\t\t * Verify Recaptcha<br \/>\n\t\t\t *\/<br \/>\n\t\t\t$show_reCAPTCHA = get_option( &#8216;theme_show_reCAPTCHA&#8217; );<br \/>\n\t\t\t$reCAPTCHA_public_key = get_option( &#8216;theme_recaptcha_public_key&#8217; );<br \/>\n\t\t\t$reCAPTCHA_private_key = get_option( &#8216;theme_recaptcha_private_key&#8217; );<\/p>\n<p>\t\t\tif ( ! empty( $reCAPTCHA_public_key ) &amp;&amp; ! empty( $reCAPTCHA_private_key ) &amp;&amp; $show_reCAPTCHA == &#8216;true&#8217; ) {<br \/>\n\t\t\t\t\/* Include recaptcha library *\/<br \/>\n\t\t\t\trequire_once( get_template_directory() . &#8216;\/recaptcha\/recaptchalib.php&#8217; );<br \/>\n\t\t\t\t$resp = recaptcha_check_answer( $reCAPTCHA_private_key,<br \/>\n\t\t\t\t\t$_SERVER[ &#8220;REMOTE_ADDR&#8221; ],<br \/>\n\t\t\t\t\t$_POST[ &#8220;recaptcha_challenge_field&#8221; ],<br \/>\n\t\t\t\t\t$_POST[ &#8220;recaptcha_response_field&#8221; ] );<\/p>\n<p>\t\t\t\tif ( ! $resp-&gt;is_valid ) {<br \/>\n\t\t\t\t\t\/* What happens when the CAPTCHA was entered incorrectly *\/<br \/>\n\t\t\t\t\techo json_encode( array(<br \/>\n\t\t\t\t\t\t&#8216;success&#8217; =&gt; false,<br \/>\n\t\t\t\t\t\t&#8216;message&#8217; =&gt; __( &#8216;The reCAPTCHA is not correct. Please try again.&#8217;, &#8216;framework&#8217; )<br \/>\n\t\t\t\t\t) );<br \/>\n\t\t\t\t\tdie;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t}<\/p>\n","protected":false},"template":"","class_list":["post-10552383","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10552383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10552383\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=10552383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}