-1

I can send the form with or without the box checked. No idea where to go here.

I have a "custom" form that accepts email addresses. An earlier uploaded .csv file is checked for that specific email address and sends the email address and set of data corresponding with that email address in the .csv file.

This all works but I need to add a reCaptcha function. So I wanted to use Googles.

Here is the code (without the check and mail function). The basic form

<form action="" method="post" enctype="multipart/form-data">
    <input type="text" name="field_name" />
    <div class="g-recaptcha" data-sitekey="6LcYnikUAAAAAMUyMmPRUlnnF-1i3pShj52unsn5"></div>
    <input type="submit" value="Versturen" />
</form>

The header contains:
<script src='https://www.google.com/recaptcha/api.js'></script>

Further info:
- The php that handles the email and file check is added after the form (also tried before the form but no difference)
- I get warnings saying it can't include wp-load.php but if I send the form it will send and deliver.

Warning: include(../../../wp-load.php): failed to open stream: File or folder doesn't exist in /home/xxx/wp-content/themes/xxx/template.php on line 39

Warning: include(../../../wp-load.php): failed to open stream: File or folder doesn't exist in /home/xxx/wp-content/themes/xxx/template.php on line 39

Warning: include(): Failed opening '../../../wp-load.php' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/xxx/wp-content/themes/xxx/template.php on line 39

Line 39: include '../../../wp-load.php';

Any idea why the reCaptcha won't work?

Interactive
  • 1,474
  • 5
  • 25
  • 57
  • Hello Interactive, you could add some javascript, to help get your form working. Please see this answer: https://stackoverflow.com/questions/29612879/google-recaptcha-how-to-make-required/29613089#29613089 – colecmc Jul 24 '17 at 17:40
  • Figured it out. I didn't implemented the verification. Feel really stupid now. Thnx tho' – Interactive Jul 25 '17 at 08:10

1 Answers1

1

It needs verification.....
Because the form is custom I needed to implement the verification. Form:

<div>
    <form action="" method="post" id="FORMID" enctype="multipart/form-data">
        <input type="text" name="field_name" /><br />
        <div class="g-recaptcha" data-sitekey="==SITEKEY=="></div>
        <input type="submit" name="Submit" id="submit" value="Send" />
    </form>
</div>
<script src='https://www.google.com/recaptcha/api.js?hl=nl'></script>
        <script type="text/javascript">
        jQuery("#submit").click(function(e){
                var data_2;
            jQuery.ajax({
                        type: "POST",
                        url: "http://www.example.com/wp-content/themes/THEME/includes/google_captcha.php",
                        data: jQuery('#FORMID').serialize(),
                        async:false,
                        success: function(data) {
                         if(data.nocaptcha==="true") {
                       data_2=1;
                          } else if(data.spam==="true") {
                       data_2=1;
                          } else {
                       data_2=0;
                          }
                        }
                    });
                    if(data_2!=0) {
                      e.preventDefault();
                      if(data_2==1) {
                        alert("Check the captcha box");
                      } else {
                        alert("Please Don't spam");
                      }
                    } else {
                        jQuery("#FORMID").submit
                   }
          });
        </script>

google_captcha.php

<?php
$data;
header('Content-Type: application/json');
error_reporting(E_ALL ^ E_NOTICE);
if(isset($_POST['g-recaptcha-response'])) {
  $captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
  $data=array('nocaptcha' => 'true');
  echo json_encode($data);
  exit;
 }
 // calling google recaptcha api.

$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=KEYSECRET&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
 // validating result.
 if($response.success==false) {
    $data=array('spam' => 'true');
    echo json_encode($data);
 } else {
    $data=array('spam' => 'false');
    echo json_encode($data);
 }
?>
Interactive
  • 1,474
  • 5
  • 25
  • 57