PHP js提醒消息,当表单发送好
问题描述:
我试图显示一个警告框,说消息发送确定,但由于某种原因,我没有看到消息。我确实有人说要检查验证码。我究竟做错了什么?所有的代码都在我的index.php文件中。所有if如果在开始时试图避免重新提交表单。 另外,我如何设计警示框?我试过使用Bootbox。 Js但没有运气。PHP js提醒消息,当表单发送好
<?php
$message['message'] = "";
if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['submit'])) {
if (isset($_POST['g-recaptcha-response']) && ($_POST["g-recaptcha-response"] != '')) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$privatekey = "--secretKey--";
$response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
$data = json_decode($response);
if (isset($data->success) AND $data->success==true) {
$to = "[email protected]";
$email = $_POST['email'];
$name = $_POST['name'];
$subject = $_POST['asunto'];
$subject2 = 'Copia de: '.$_POST['asunto'];
$message = $name . " " . "escribio lo siguiente:" . "\n\n" . $_POST['message'];
$message2 = "Le enviamos una copia de su mensaje " . $name . "\n\n" . $_POST['message'];
$headers = "From:" . $email;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($email,$subject2,$message2,$headers2);
//echo "La consulta se envió correctamente. Gracias! " . $name . ", lo contactaremos a la brevedad.";
echo '<script type="text/javascript">alert("El mensaje se envió correctamente. Muchas gracias!");</script>';
//Back to the web
header('Location: index.php');
}
} else {
echo '<script type="text/javascript">alert("Por favor tildar el captcha!");</script>';
//$_SESSION['form'] = filter_input_array(INPUT_POST);
}
}
?>
形式:
<div class="col-md-4 to-animate">
<h3 class="section-title">Escribinos</h3>
<form class="contact-form" action="" method="post" id="form">
<div class="form-group">
<label for="name" class="sr-only">Nombre</label>
<input type="name" class="form-control" name="name" id="name" placeholder="Nombre y Apellido" required title="Por favor ingrese su nombre y apellido" value="<?php echo (isset($_POST['name']) ? htmlspecialchars($_POST['name']) : ''); ?>" />
</div>
<div class="form-group">
<label for="asunto" class="sr-only">Asunto</label>
<input type="asunto" class="form-control" name="asunto" id="asunto" placeholder="Asunto" required title="Por favor ingrese el asunto" value="<?php echo (isset($_POST['asunto']) ? htmlspecialchars($_POST['asunto']) : ''); ?>" />
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="email" class="form-control" name="email" id="email" placeholder="Email" required title="Por favor ingrese un mail" value="<?php echo (isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''); ?>" />
</div>
<div class="form-group">
<label for="message" class="sr-only">Mensaje</label>
<textarea class="form-control" id="message" name="message" rows="7" placeholder="Mensaje" required title="Por favor ingrese un mensaje mayor a 10 caractéres."><?php echo (isset($_POST['message']) ? htmlspecialchars($_POST['message']) : ''); ?></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" id="btn-submit" class="btn btn-send-message btn-md" value="ENVIAR">
</div>
<div class="g-recaptcha" data-sitekey="--Sitekey--" data-callback="callback"></div>
</form>
</div>
答
不知道该代码的其余部分,或者如果这是问题 - 但你不应该在“如果” statetement使用“AND
” - 它应该是:
if (isset($data->success) && $data->success==true) {...
答
去除
header('Location: index.php');
后
显示消息。不要问我为什么。