【发布时间】:2020-03-18 21:00:23
【问题描述】:
按下按钮(输入提交)后,是否可以在我的网站上显示 HTML 的回显内容,POST 请求是在同一网站上发出的。
当我按下按钮时,它会刷新网站并发出POST 请求,但我不希望它自动刷新网站,如果可能的话,我想在当前网站上显示警报。
<button id="submit" type="submit" class="btn btn-darkred rounded mr-xl-5" style="width:300px">LOGIN</button>
这是 PHP 代码
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$secretKey = 'captchaSecret';
$captcha = $_POST['g-recaptcha-response'];
if(!$captcha){
echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
exit;
}
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
} else {
echo 'successful';
}
}
?>
这是我希望在当前网站上显示的内容,而不是带有警报的空白页面:
echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
【问题讨论】:
-
你的
<form action=是什么? -
<form class="mt-5 form-material" style="width:300px" method="POST" action="registration">注册的是同一个站点 -
在这种情况下,您只需将
action="registration"更改为action=""。 -
我实际上的意思是刷新页面并向我显示作为我的警报的 echo 的内容,我实际上希望我的警报显示在同一页面上而不是空白页面上。
-
如果您想在不刷新页面的情况下更新页面,则需要使用 AJAX(通过 JavaScript)。
标签: php html bootstrap-4