0
請不要說我對php不太好,所以所有的幫助將不勝感激。Display die();消息與表格
不管怎麼說,我有這樣的形式:
<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>
當發送的形式,我想顯示在同一頁面上die消息。此時的消息顯示在另一頁上。
我mail.php
文件的該塊發送郵件:
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = '[email protected]'; //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>");
,這阿賈克斯應該做的伎倆:
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;
}
如果Ajax有效,爲什麼不使用它? – Hope4You
我想你需要使用'error:'回調來獲得腳本死亡時的響應。 – Barmar
@ Hope4You,我有這個AJAX代碼,我在我的.js文件中提到,但它由於某種原因o.O不起作用?這就是我需要幫助的。 – idjuradj