简体   繁体   English

如何检查表格是否已提交

[英]How to check if form was submitted

My question is how to check which form was submitted if I have 2 different forms with the same name, and I can't change the name. 我的问题是,如果我有两个具有相同名称的不同表单,并且无法更改名称,该如何检查提交的表单。

For example I have 2 forms and 2 php scripts that evaluate them: 例如,我有2种形式和2种评估它们的php脚本:

 <form action=mypage.php method=post> <input type=text name=name> <input type=submit name=ok value=ok> </form> 

<?php
  if(isset($_POST['ok'])) {
    $name=$_POST['name'];
  }
?>

 <form action=mypage.php method=post> <input type=text name=pass> <input type=submit name=ok value=ok> </form> 

<?php
  if(isset($_POST['ok'])) { // <- here is wrong
    $pass=$_POST['pass]']; // this code is not executing
  }
?>

How I can differentiate these two submits without changing their names? 如何在不更改名称的情况下区分这两个提交者?

PS I can't bring the (Forms) together. 附言:我无法将(表格)放在一起。

One solution is to add a hidden input on both forms: 一种解决方案是在两种形式上添加隐藏的输入:

<input type="hidden" name="form1" value="name" />

and: 和:

<input type="hidden" name="form2" value="pass" />

Then to check which one has been submitted: 然后检查提交了哪一个:

if(isset($_POST['ok']) && isset($_POST['form1'])){

// For the first form

}

And: 和:

if(isset($_POST['ok']) && isset($_POST['form2'])){

// For the second form

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM