[英]Display die(); message on the same page as form
I am a beginner with PHP.我是 PHP 的初学者。
Anyway, I have this form:无论如何,我有这个表格:
<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>
When the form is sent, I want to display a die message on the same page.发送表单时,我想在同一页面上显示一条死亡消息。 The message at this point shows on another page.此时的消息显示在另一页上。
This chunk of my mail.php
file sends the mail:我的这部分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>");
and this Ajax should do the trick:这个 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;
}
die('string')的意思是,停止运行并转储'string',它应该起作用!
it is the same page (mail.php) but you are calling die before the html is displayed so move your die line after the html code它是同一页面(mail.php),但您在显示 html 之前调用 die 所以将您的 die 线移动到 html 代码之后
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.