2014-10-03 2 views
0

Я создал плагин Google ReCaptcha PHP на этом сайте:PHP Recaptcha не работает

http://benliger.webatu.com/

Вы можете видеть, что отображает отлично под контакт, однако после добавления в нужном PHP в мой form_process файл форма все равно отправляется независимо от того, заполняется ли reCaptcha. Вот мой PHP код, который находится в form_process файле:

<?php 

    //Check if POST data is set, and not empty, else it will do this every single time, submitted or not 

    require_once('recaptchalib.php'); 
     $privatekey = "6Le2a_oSAAAAAJ81_yQvCelFMIHiUcG_k6u0S1fd"; 
     $resp = recaptcha_check_answer ($privatekey, 
            $_SERVER["REMOTE_ADDR"], 
            $_POST["recaptcha_challenge_field"], 
            $_POST["recaptcha_response_field"]); 

     if (!$resp->is_valid) { 
     // What happens when the CAPTCHA was entered incorrectly 
     die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . 
      "(reCAPTCHA said: " . $resp->error . ")"); 
     } else { 



    if(isset($_POST) && !empty($_POST)) 
    { 

     $mail_to = '[email protected]'; // specify your email here 

     // Assigning data from the $_POST array to variables 
     $name = $_POST['sender_name']; 
     $mail_from = $_POST['sender_email']; 
     $phone = $_POST['sender_phone']; 
     $message = $_POST['sender_message']; 

     // Construct email subject 
     $subject = 'enquiry ' . $name; 

     // Construct email body 
     $body_message = 'From: ' . $name . "\r\n"; 
     $body_message .= 'E-mail: ' . $mail_from . "\r\n"; 
     $body_message .= 'Phone: ' . $phone . "\r\n"; 
     $body_message .= 'Message: ' . $message; 

     // Construct email headers 
     $headers = 'From: ' . $mail_from . "\r\n"; 
     $headers .= 'Reply-To: ' . $mail_from . "\r\n"; 

     $mail_sent = mail($mail_to, $subject, $body_message, $headers); 

     if ($mail_sent == true){ 
      //Echo the message now, because it will be catched in your jQuery listerener (see code below) 
      echo 'Thanks for getting in touch!'; 




     } else { 
      //Echo the message now, because it will be catched in your jQuery listerener (see code below) 
      echo 'Message not sent :(Please, get in contact with me directly: [email protected]'; 
     } 
     //This exit; is important, else the alert box will be full of the further html code 
     exit; 

    } 
    } 
    ?> 

И мой HTML:

<form name="myForm" action="form_process.php" method="POST"> 

<?php 
      require_once('recaptchalib.php'); 
      $publickey = "6Le2a_oSAAAAAEHu4u35QWlLzxzCYB1JnhFoI0u5"; // you got this from the signup page 
      echo recaptcha_get_html($publickey); 
     ?> 

.... и остальная часть моей формы здесь

Может быть, стоит отметить, что я послать кнопка выглядит так:

<input class="sendbutton" type="submit" name="send_message" value="Send"> 

Javascript:

$(document).on('submit','form',function(e){ 
    //Prevent the default action 
    e.preventDefault(); 

var form = $(this); 
    //Create an array of input values 
    var data = $(this).serializeArray(); 
    //Do the ajax request 
    $.post('form_process.php',data,function(responseMessage){ 
resetForm(form); 
     //Alert your message 
$(".mycontactform").html('<p>Thanks for getting in touchaaa!</p>'); 

     //alert(responseMessage); 
    }); 

}); 
+0

ли вы используете правую клавишу при генерации? Я тоже не могу найти проблему. – Wouter0100

+0

Попробуйте изменить require_once. –

+2

Вы проверяете CAPTCHA на достоверность, прежде чем вы даже проверите, действительно ли запрос был сделан через POST ... это мало смысла. – CBroe

ответ

2

Ошибка в вашем Jquery код .whatever в отклике вы заменяете его с <p>Thanks for getting in touchaaa!</p>

использования alert(responseMessage), чтобы увидеть ответ

$(".mycontactform").html('<p>Thanks for getting in touchaaa!</p>'); так заменить

с alert(responseMessage)

+0

Решил! Теперь мой единственный вопрос: могу ли я получить его так, чтобы, когда форма была отправлена ​​с Captcha правильно заполнена, она будет эхо-сообщение в html, как раньше, а не через бокс javascript? –

+1

$ (".mycontactform").HTML (responseMessage); –

+0

один последний вопрос, не предположим, что theres способ сделать сообщение ответа из неудавшейся формы вызывается в alert (responseMessage) и успешный, чтобы опубликовать в html, как и ваше предложение? –

Смежные вопросы