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

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

问题描述

我正在设置一个表单,其中我需要两个操作"(两个按钮):

1 - 提交此表单以供批准"
2 - 保存此应用程序以备后用"

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

EG:


我需要将这两种提交选项组合成一种形式.

我进行了一些基础研究,但找不到关于这是否可行的明确答案,和/或任何用于解决方法链接的好资源.

提前致谢.

解决方案

正如@AliK 提到的,这可以通过查看提交按钮的值轻松完成.

当您提交表单时,未设置的变量将评估为 false.如果您将两个提交按钮都设置为同一个表单的一部分,您只需检查并查看已设置的按钮.

HTML:

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

PHP

<前>如果($_POST[保存"]){//用户点击保存按钮,进行相应处理}//你可以做一个else,但我更喜欢单独的语句如果($_POST[批准"]){//用户点击提交审批按钮,进行相应处理}

编辑<小时>如果您不想更改 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天全站免登陆