所以,我想将不同的行为绑定到Zend PHP表单上的同一个按钮。下面是我现在的代码示例:
if (isset($_POST['submit'])) {
$this->_helper->messenger->addSuccess('Are you sure you would like to delete this link? The link and all statistics tied to it will be permanently deleted if you take this option.');
if (isset($_POST['submit'])) {
...
}
}
然而,无论我点击多少次提交,这段代码似乎都在继续显示消息。我的问题是
- 我想做的是可能的吗?
- 如果我想要的行为无法实现,我该怎么办?
根据您想要执行的操作更改按钮的值。例如,默认情况下将该值设置为1,当提交一次时,动态地将该按钮的值设置为2。现在根据$_POST['submit']
的值显示警报或采取行动。
示例代码:
if (isset($_POST['submit'])) {
if ($_POST['submit'] == 1) {
//submitted first time
$this->_helper->messenger->addSuccess('Are you sure you would like to delete this link? The link and all statistics tied to it will be permanently deleted if you take this option.');
} else if ($_POST['submit'] == 2) {
// second time, so take action
...
}
}