PHP的两种表单数据提交方式

时间:2021-10-12 17:14:10

1 通过隐藏表单提交

    //通过隐藏表单提交
if ($_POST['action'] == 'register'){
echo '你提交了数据';
exit();
}
?> <!DOCTYPE html>
<head>
</head>
<body>
<div id='register'>
<form method="post" name="register" action="register.php">
<input type="hidden" name="action" value="register" />
<ul>
<h2>请认真填写一下内容</h2>
<li>用&#8194户&#8194名:<input type='text' name='username' class='text' />(*必填,至少两位)</li>
<li>密&#12288&#12288码:<input type='password' name='password' class='text' />(*必填,至少两位)</li>
<li><input type='submit' value='提交' /></li>
</ul>
</form>
</div>
</body>

2 通过?后的后缀提交数据

<?php
if ($_GET['action'] == 'register'){
echo '你提交了数据';
exit();
}
?> <!DOCTYPE html>
<head>
</head>
<body>
<div id='register'>
<form method="post" name="register" action="register.php?action=register">
<ul>
<h2>请认真填写一下内容</h2>
<li>用&#8194户&#8194名:<input type='text' name='username' class='text' />(*必填,至少两位)</li>
<li>密&#12288&#12288码:<input type='password' name='password' class='text' />(*必填,至少两位)</li>
<li><input type='submit' value='提交' /></li>
</ul>
</form>
</div>
</body>