douniao8687 2018-12-18 20:34
浏览 142

reCAPTCHA找不到用户提供的函数:onloadCallback

When I load my page, I get this error in the console

"reCAPTCHA couldn't find user-provided function: onloadCallback"

I have followed a tutorial from phppot for a PHP with Google Recaptcha. When I click submit without doing the recaptcha, it gives me an error saying that I need to complete it. However, when I do complete it, it shows my loading symbol in a never ending loop and doesn't actually send the email. I have the following codes below:

    $(document).ready(function (e){
    $("#frmContact").on('submit',(function(e){
        e.preventDefault();
        $("#mail-status").hide();
        $('#send-message').hide();
        $('#loader-icon').show();
        $.ajax({
            url: "contact.php",
            type: "POST",
            dataType:'json',
            data: {
            "name":$('input[name="name"]').val(),
            "email":$('input[name="email"]').val(),
            "phone":$('input[name="phone"]').val(),
            "content":$('textarea[name="content"]').val(),
            "g-recaptcha-response":$('textarea[id="g-recaptcha-response"]').val()},             
            success: function(response){
            $("#mail-status").show();
            $('#loader-icon').hide();
            if(response.type == "error") {
                $('#send-message').show();
                $("#mail-status").attr("class","error");                
            } else if(response.type == "message"){
                $('#send-message').hide();
                $("#mail-status").attr("class","success");                          
            }
            $("#mail-status").html(response.text);  
            },
            error: function(){} 
        });
    }));
});

is in my section on top of my contactus.php page.

Then I have the following for my contact.php page:

 if($_POST)

{

$user_name      = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$user_email     = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$user_phone     = filter_var($_POST["phone"], FILTER_SANITIZE_STRING);
$content   = filter_var($_POST["content"], FILTER_SANITIZE_STRING);

if(empty($user_name)) {
    $empty[] = "<b>Name</b>";       
}
if(empty($user_email)) {
    $empty[] = "<b>Email</b>";
}
if(empty($user_phone)) {
    $empty[] = "<b>Phone Number</b>";
}   
if(empty($content)) {
    $empty[] = "<b>Comments</b>";
}

if(!empty($empty)) {
    $output = json_encode(array('type'=>'error', 'text' => implode(", ",$empty) . ' Required!'));
    die($output);
}

if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation
    $output = json_encode(array('type'=>'error', 'text' => '<b>'.$user_email.'</b> is an invalid Email, please correct it.'));
    die($output);
}

//reCAPTCHA validation
if (isset($_POST['g-recaptcha-response'])) {

    require('component/recaptcha/src/autoload.php');        

    $recaptcha = new \ReCaptcha\ReCaptcha(SECRET_KEY, new \ReCaptcha\RequestMethod\SocketPost());

    $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);

      if (!$resp->isSuccess()) {
            $output = json_encode(array('type'=>'error', 'text' => '<b>Captcha</b> Validation Required!'));
            die($output);               
      } 
}

$toEmail = "member@testdomain.com";
$mailHeaders = "From: " . $user_name . "<" . $user_email . ">
";
if (mail($toEmail, "Contact Mail", $content, $mailHeaders)) {
    $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .', thank you for the comments. We will get back to you shortly.'));
    die($output);
} else {
    $output = json_encode(array('type'=>'error', 'text' => 'Unable to send email, please contact'.SENDER_EMAIL));
    die($output);
}

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败