0

除了保持在同一页面上的成功消息外,我有以下表格有效。

我一直在绞尽脑汁,但在这一点上它是糊状的。

**问题我需要关闭表单并在提交表单时显示“成功”DIV。

现在我唯一能做的就是通过使用标题让它进入thanks.php 页面。

所有代码都在 jsfiddle:http: //jsfiddle.net/webs4me/hyArd/1/

除了下面的 send.hello.php: - 谢谢

   <?php
   // Clean up the input values
   foreach($_POST as $key => $value) {
     if(ini_get('magic_quotes_gpc'))
       $_POST[$key] = stripslashes($_POST[$key]);

     $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
   }

   // Honeypot don't send - THIS WILL BE HIDDEN LATER
   if(!empty($_POST["confirm_email"])) {
   header("location:spam.php");exit;
   }

   // Assign the input values to variables for easy reference
   $name = $_POST["name"];
   $email = $_POST["email"];
   $confirm = $_POST["confirm_email"];
   $phone = $_POST["phone"];
   $message = $_POST["message"];

   // Send the email *********** enter your email address and message info 
   $to = "myemail@myemail.com"; 
   $subject = "Website message: $name";
   $message = "From:\n$name\n\nEmail:\n$email\n\nPhone:\n$phone\n\nMessage:\n$message";
   $headers = "From: $email";

   mail($to, $subject, $message, $headers);

   header('location: thanks.php');


   ?>
4

1 回答 1

1

由于您已经在使用 JQuery,请使用$.POST

http://api.jquery.com/jQuery.post/

$.ajax({
    type: "POST",
    url: url,
    data: data,
    success: success,
    dataType: dataType
});
  • data将从所有表单输入的值构造。
  • url将是hello.php页面
  • 您可以onsubmit向表单添加一个函数,或者取出提交按钮并添加一个常规输入按钮,并onclick调用一个构建data和调用 $.POST的函数
于 2013-09-30T20:44:08.530 回答