我希望在表单提交后有一个提醒框,而不是重定向到thank-you.html

I want an alert box after form submit not redirect to thank-you.html

本文关键字:重定向 html thank-you 表单提交 有一个 我希望      更新时间:2023-09-26

我想在提醒框中说声谢谢,而不是重定向到thank-you.html

这是我的代码:

<?php
if (!isset($_POST['submit']))
{
    //This page should not be accessed directly. Need to submit the form.
    echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$contact = $_POST['contact']$message = $_POST['message'];
//Validate first
if (empty($name) || empty($visitor_email))
{
    echo "Name and email are mandatory!";
    exit;
}
if (IsInjected($visitor_email))
{
    echo "Bad email value!";
    exit;
}
$email_from = 'tom@amazing-designs.com'; //<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.'n" . "Here is the message:'n $message" .
$to = "tom@amazing-designs.com"; //<== update the email address
$headers = "From: $email_from 'r'n";
$headers .= "Reply-To: $visitor_email 'r'n";
//Send the email!
mail($to, $email_subject, $email_body, $headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');

我不想将页面重定向到thank-you.html。我只想用";谢谢";。

删除标头('Location:thank-you.html');并添加javascript

<script>
    alert('Thank you!!!');
</script>

header()部件替换为:printf("<script> alert('Thank You!'); </script>");