不同的行为取决于表单按钮点击?

时间:2014-08-07 19:00:09

标签: php

所以,我想将不同的行为绑定到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. 如果我的行为无法实现,我该怎么办?

1 个答案:

答案 0 :(得分:0)

根据您要执行的操作更改按钮的值。例如,默认情况下将值设置为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
        ...
    }
}