具有多个“动作”的HTML表单 [英] HTML form with multiple "actions"

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

问题描述



1 - 提交此表格以供审批

2 - 将此应用程序保存以备后用



如何创建支持多个操作的HTML表单?

EG

< form class =form-horizo​​ntalaction =submit_for_approval.php> code>

< form class =form-horizo​​ntalaction =save_for_later.php>



我需要将这两个选项合并为一个表单。



我做了一些基础研究,但找不到确切的答案是否可能,和/或任何良好的资源链接的解决方法。



预先感谢。



当你提交表单时,未设置的变量将评估为false。如果您将两个提交按钮设置为同一表单的一部分,则可以检查并查看设置了哪个按钮。


$ b HTML:

 
< input type =submitvalue =Savename =save/>
< input type =submitvalue =Submit for Approvalname =approve/>
< / form>

PHP

 
if($ _ POST [save]){
//用户点击保存按钮,相应地处理
}
//你可以做别的,但我更喜欢单独的语句
if($ _ POST [approve]){
//用户点击Submit for Approval按钮,相应地处理
}

编辑



如果您不想更改PHP设置,请尝试以下操作: http://pastebin.com/j0GUF7MV

这是@AliK所奉行的JavaScript方法。



相关:


I'm setting up a form wherein I need two "actions" (two buttons):

1 - "Submit this form for approval"
2 - "Save this application for later"

How do I create an HTML form that supports multiple "actions"?

EG:

<form class="form-horizontal" action="submit_for_approval.php">
<form class="form-horizontal" action="save_for_later.php">

I need to combine these two options-for-submitting into one form.

I did some basic research but couldn't find a definitive answer as to whether or not this is possible, and/or any good resources to links for a workaround.

Thanks in advance.

解决方案

As @AliK mentioned, this can be done easily by looking at the value of the submit buttons.

When you submit a form, unset variables will evaluate false. If you set both submit buttons to be part of the same form, you can just check and see which button has been set.

HTML:

<form action="handle_user.php" method="POST" />
  <input type="submit" value="Save" name="save" />
  <input type="submit" value="Submit for Approval" name="approve" />
</form>

PHP

if($_POST["save"]) {
  //User hit the save button, handle accordingly
}
//You can do an else, but I prefer a separate statement
if($_POST["approve"]) {
  //User hit the Submit for Approval button, handle accordingly
}

EDIT


If you'd rather not change your PHP setup, try this: http://pastebin.com/j0GUF7MV
This is the JavaScript method @AliK was reffering to.

Related:

这篇关于具有多个“动作”的HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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