显示模具();与表单在同一页面上的消息

时间:2012-09-22 00:33:56

标签: php die

请注意,我对php不是那么好,所以非常感谢所有帮助。

无论如何,我有这样的表格:

<form method="post" action="mail.php" id="contactform">
    <div class="stage cf">
        <input type="text" name="contactname" id="contactname" placeholder="Name" class="required" role="input" aria-required="true" />
    </div>
    <div class="stage cf">
        <input type="text" name="email" id="useremail" placeholder="Email" class="required email" role="input" aria-required="true" />
    </div>
    <div class="stage cf">
        <input type="text" name="subject" id="subject" placeholder="Subject" class="required" role="input" aria-required="true" />
    </div>
    <div class="stage cf">
        <textarea rows="5" name="message" id="message" placeholder="Message" class="required" role="textbox" aria-required="true"></textarea>
    </div>                                      
        <input type="submit" value="Send Message" name="submit" id="submitButton" title="SendMessage" />
    <div id="response"></div>
</form>

发送表单时,我想在同一页面上显示一条骰子消息。此时的消息显示在另一页上。

我的mail.php文件的这一块发送邮件:

//If there is no error, send the email
if(!isset($hasError)) {
    $emailTo = 'test@randommail.com'; //Put your own email address here
    $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
    $headers = "From: $email";

    mail($emailTo, $subject, $body, $headers);
    $emailSent = true;

}
die("<span class='success'>Success! Your message has been sent.</span>");

这个Ajax应该可以解决问题:

submitHandler: function(form) {
    $("#send").attr("value", "Sending...");
    $(form).ajaxSubmit({
        success: function(responseText, statusText, xhr, $form) {
            $(form).slideUp("fast");
            $("#response").html(responseText).hide().slideDown("fast");
        }
    });
    return false;
}

1 个答案:

答案 0 :(得分:1)

die('string')表示停止运行并转储'string' 它应该工作!