[英]Showing a message in the same page after submitting a form
I have a simple HTML form with a name & email address field and a submit button. 我有一个简单的HTML表单,其中包含名称和电子邮件地址字段以及一个提交按钮。
After filling in the form and submitting it, I want a message such as "Thank you for your response" to appear on the same page. 填写并提交表格后,我希望在同一页面上显示一条消息,例如“谢谢您的答复”。
I'm looking for a easy clean PHP fix for this. 我正在为此寻找一个简单干净的PHP修复程序。 I want all the code to stay on one page (Not separate it into two different files).
我希望所有代码都停留在一页上(不要将其分成两个不同的文件)。
I've been searching on Google, but they have much more complex situations. 我一直在Google上进行搜索,但情况更为复杂。
Your help is greatly appreciated. 非常感谢您的帮助。 Thanks.
谢谢。
EDIT: I want the form to disappear after pressing submit and just show the "Thank you for your response" message. 编辑:我希望表单在按提交后消失,只是显示“谢谢您的回复”消息。 I forgot to mention that.
我忘了提。 Sorry.
抱歉。
<form>
<p><span>Name</span><input class="contact" type="text" name="your_name" value="" /></p>
<p><span>Email Address</span><input class="contact" type="text"
name="your_email" value="" /></p>
<p style="padding-top: 15px"><span> </span><input class="submit"
type="submit" name="contact_submitted" value="submit" /></p>
</form>
please try below code. 请尝试以下代码。
<?php
if($_POST) {
echo "Thank you for your response";
}
?>
<form name="test" action="" method="post">
<p><span>Name</span><input class="contact" type="text" name="your_name" value="" /></p>
<p><span>Email Address</span><input class="contact" type="text"
name="your_email" value="" /></p>
<p style="padding-top: 15px"><span> </span><input class="submit"
type="submit" name="contact_submitted" value="submit" /></p>
</form>
Would something like the following help? 以下内容会有所帮助吗? Essentially, when you hit submit, some special variables are set in the $_POST array, and you can access those.
本质上,当您单击Submit时,会在$ _POST数组中设置一些特殊变量,您可以访问它们。 If those variables are set when we're building the page in PHP, then we can do some processing/send an email/show a different response page.
如果在用PHP构建页面时设置了这些变量,那么我们可以进行一些处理/发送电子邮件/显示其他响应页面。
<?php
if (array_key_exists($_POST['your_email'])) /* and other validation */ {
?>
<p>Thanks!</p>
<?php } else { ?>
<form action="POST">
<p><span>Name</span><input class="contact" type="text" name="your_name" value="" /></p>
<p><span>Email Address</span><input class="contact" type="text"
name="your_email" value="" /></p>
<p style="padding-top: 15px"><span> </span><input class="submit"
type="submit" name="contact_submitted" value="submit" /></p>
</form>
<?php } ?>
in you form validate page 在您的表单验证页面中
header('location: ../page.php?case=Thank you for your response');
in your page 在您的页面中
<?php print $_GET['case']; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.