为什么在表单中使用php post方法中的隐藏框
嗨,我是在新的Php 我在问为什么我们使用隐藏文本框和给定值=1为什么在表单中使用php post方法中的隐藏框,php,forms,Php,Forms,嗨,我是在新的Php 我在问为什么我们使用隐藏文本框和给定值=1 <input type="text" name="form_submitted" value="1"/> <html> <head> <title>Registration Form</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <
<input type="text" name="form_submitted" value="1"/>
<html>
<head>
<title>Registration Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php if (isset($_POST['form_submitted'])): ?>
<?php if (!isset($_POST['agree'])): ?>
<p>You have not accepted our terms of service</p>
<?php else: ?>
<h2>Thank You <?php echo $_POST['firstname']; ?></h2>
<p>You have been registered as <?php echo $_POST['firstname'] . ' ' . $_POST['lastname']; ?> </p>
<p> Go <a href="sample.php" >back</a> to the form</p>
<?php endif; ?>
<?php else: ?>
<h2>Registration Form</h2>
<form action="sample.php" method="POST">
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname"><br>
Agree to Terms of Service: <input type="checkbox" name="agree"> <br>
**<input type="hidden" name="form_submitted" value="1"/>**
<input type="submit" value="Submit">
</form>
<?php endif; ?>
</body>
</html>
登记表
您尚未接受我们的服务条款
非常感谢。
您已注册为
转到表格
登记表
名字:
姓氏:
同意服务条款:
****
在这种情况下,开发人员之所以这样做,是因为它在第一个IF语句中使用
if (isset($_POST['form_submitted'])):
提交表单时,表单将发送到同一个文件。提交表单时,可以通过php中的$\u POST
参数访问表单值。因此,如果设置了$\u POST['form\u submitted']
,则他执行以下代码,如果未设置,则执行else:
中的代码
我还要说,这段代码不是一个处理表单提交的好例子,应该加以改进 开发人员使用
,因为有时他们将其用作表单提交的参考。他们可以在条件下使用它,也可以在hidden
输入中使用任何功能
他们没有显示准确的输入(输入文本),而是将其隐藏起来,以便更简洁。您的问题非常不清楚。尝试编辑问题,以便我们准确地知道您需要帮助的内容无论您为什么使用隐藏输入,它的位置都在
元素中,而不是脚本顶部。