如何检测Zend Framework表单上按下了哪个提交按钮? [英] How do I detect which submit button was pressed on a Zend Framework form?

查看:82
本文介绍了如何检测Zend Framework表单上按下了哪个提交按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Zend Framework表单,其中有两个提交按钮

I have a Zend Framework form that has two submit buttons

$changes = new Zend_Form_Element_Submit('save_changes');
$changes->setLabel('Save Changes');

$delete = new Zend_Form_Element_Submit('delete');
$delete->setLabel('Delete');

其中的HTML呈现如下:

Which renders HTML like such:

<input type="submit" name="save_changes" id="user_save_changes" value="Save Changes" >
<input type="submit" name="delete" id="user_delete" value="Delete" >

在控制器中,如何确定用户按下了哪个按钮?

In the controller, how do I determine which button the user pressed?

推荐答案

在您的情况下,您应该只能检查

In your case you should just be able to check

if(isset($_POST['save_changes'])
// or
if(isset($_POST['delete'])

因为将仅提交单击按钮的值.

Since only the value of the clicked button will be submitted.

通常,您将两个按钮都命名为相同的名称(例如,动作),然后将 您想要执行的操作的价值.不幸的是,这不能很好地工作 与IE.查看此页面,以获取有关针对多个网站的不同解决方案的更多信息 提交按钮.

Usually you give both buttons the same name (e.g. action) and then set the value to the action you want to perform. Unfortunately that doesn't work very well with IE. Check this page for more information about different solutions for multiple submit buttons.

这篇关于如何检测Zend Framework表单上按下了哪个提交按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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