[英]php two self submitting forms on one page
我有一个网页表单,提交自己进行PHP动作。 我想在同一个网页上添加第二个表单,这个表单也可以自我提交,但我没有运气找到适合我的设置的解决方案。 这是我的网页的样子。
首先,它检查页面是否已经提交,如果已经提交,它会重定向到其他地方。
if($_SERVER['REQUEST_METHOD'] == "POST") {
header("Location: viewcustomers.php");
}
接下来,表单本身。
<form id="addCustomer" method="POST" action=""> ..stuff.. </form>
然后,最后我的表格动作。
if('POST' == $_SERVER['REQUEST_METHOD']) {
..phpstuff..
}
我如何调整此表单操作(或添加另一个)以区分两种不同的表单?
谢谢。
简单!
<?php
if(isset($_POST['action']) && $_POST['action'] == 'form1') {
// Form 1
} else if(isset($_POST['action']) && $_POST['action'] == 'form2') {
// Form 2
}
?>
<form action="#" method="post">
<input type="hidden" name="action" value="form1" />
</form>
<form action="#" method="post">
<input type="hidden" name="action" value="form2" />
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.