回声显示空白屏幕后的Php

时间:2017-07-07 13:36:24

标签: javascript php

显示回显后,当你点击“确定”时,它只会转到没有显示任何内容的php文件(所以我最终得到一个空白屏幕),这种情况发生了两次,我该如何修复它?

显示第二个回显后,当你点击“确定”时,它必须返回页面,这样用户才能进行reCAPTCHA,现在它只是转到没有显示任何内容的php文件(所以我最后再次出现一个空白的屏幕)

<?php
// grab recaptcha library
require_once "recaptchalib.php";

// your secret key
$secret = "secretkey";

// empty response
$response = null;

// check secret key
$reCaptcha = new ReCaptcha($secret);

// if submitted check response
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse(
    $_SERVER["REMOTE_ADDR"],
    $_POST["g-recaptcha-response"]
);
}

if ($response != null && $response->success) {
if(isset($_POST['submit'])) {
$to = "mail@hotmail.com";
$subject = "Voorstel ---.synology.me";
$suggest = $_POST['comment'];

$body = " NL\n Suggestie: $suggest\n";

echo "<script>alert('Je voorstel is verstuurd, wij proberen dit zo snel mogelijk te verwezelijken!');</script>";
//after previous echo is displayed, when you click 'ok', it just goes to the php file which displays nothing (so I end up with a blank screen)
$headers = "From: mail2@hotmail.com" . "\r\n";
mail($to, $subject, $body, $headers);
} else {
echo "Er ging iets mis, probeer opnieuw of contacteer de administrator op mail2@hotmail.com!";
}

} else {
echo "<script>alert('Vul de Captcha correct in!');</script>";
//after previous echo is displayed, when you click 'ok', it must go back to the page so the user can do the reCAPTCHA
//now it just goes to the php file which displays nothing (so I end up with a blank screen)
}
?>

1 个答案:

答案 0 :(得分:3)

取而代之的是一个警报,如何确认重定向页面?

<script>
if(confirm('Vul de Captcha correct in!')){
  window.location.href = "yourpage.php";
}
</script>

请勿忘记确保您的回音格式正确。

echo "<script>
    if(confirm('Vul de Captcha correct in!')){
        window.location.href = 'yourpage.php';
    }
</script>";

要获得相同的效果,无论选择如何,只需使用if语句来解释它。

<script>
    if(confirm('Vul de Captcha correct in!')){
      window.location.href = "yourpage.php";
    }else{
      window.location.href = "yourpage.php";
    }
 </script>