多个HTML表单在一个页面上 [英] Multiple HTML Forms on One Page

查看:132
本文介绍了多个HTML表单在一个页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有多个带有单独提交表单的HTML标记,我怎么知道哪个时间发布在处理表单数据的PHP文件中?

解决方案

最简单的方法是为表单指定唯一的提交按钮。你也可以使用这个,如果你有一个SINGLE表单的多个提交按钮(例如 - 提交并保存,提交并返回,提交和退出)

 < input type =submitname =actionvalue =Save> 
< input type =submitname =actionvalue =Return>
< input type =submitname =actionvalue =Exit>

$ _POST数组(或$ _GET / $ _ REQUEST)将包含关键字action (无论是否点击)。

通常,我避免传递不必要的隐藏文本字段等,只是为了让代码更加简洁干净。



所以。对于您的应用程序,我会给您的提交按钮值如下:

 < form id =Form1> 
< input type =submitname =actionvalue =Form1>
< / form>

< form id =Form2>
< input type =submitname =actionvalue =Form2>
< / form>

< form id =Form3>
< input type =submitname =actionvalue =Form3>
< / form>


If I have multiple HTML tags with separate submit forms, how do I know which when was posted in the PHP file that processes the form's data?

解决方案

The easiest way is to name your submit buttons unique to the form. You can also use this if you have multiple submit buttons for a SINGLE form (eg - submit and save, submit and return, submit and exit)

 <input type="submit" name="action" value="Save">
 <input type="submit" name="action" value="Return">
 <input type="submit" name="action" value="Exit">

The $_POST array (or $_GET/$_REQUEST) will contain the key "action" with the value of the enacted button (whether clicked or not).

As a rule, I avoid passing hidden text fields, etc, that are unnecessary - simply to keep the code more clean.

So. For your application, I'd give your submit button values as such:

<form id="Form1">
  <input type="submit" name="action" value="Form1">
</form>

<form id="Form2">
 <input type="submit" name="action" value="Form2">
</form>

<form id="Form3">
 <input type="submit" name="action" value="Form3">
</form>

这篇关于多个HTML表单在一个页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆