0

我有这两个按钮,

<?php echo (($active_players >= 25 && !$active_players_check_bypass) ? $html->submit('Submit Registration', array('onclick'=>'return window.confirm("You have reached your maximum allowable players per team. In order to register this player, you must pay the $25.00 required overage fee in order to continue. Do you wish to continue with the registration?")')) : $html->submit('Submit Registration'));
  echo $html->submit('Register Player using Registration Credits', array('id'=>'submitregistrationusingcredits')); // this will use the credits of the team
?>

第一个按钮是Submit Registration,另一个是Register Player using Registration Credits,现在有没有办法知道我点击了哪个按钮?我正在使用CakePHP并且我对此很陌生,有没有办法知道我点击了哪个按钮,以便在我的控制器中验证表单时,我将能够知道我点击了哪个按钮并拥有属于每个按钮的进程?谢谢。

4

2 回答 2

1

在每个提交按钮上设置名称属性。

echo (($active_players >= 25 && !$active_players_check_bypass) ? $html->submit('Submit Registration', array('name'=>'submit1a', 'onclick'=>'return window.confirm("You have reached your maximum allowable players per team. In order to register this player, you must pay the $25.00 required overage fee in order to continue. Do you wish to continue with the registration?")')) : $html->submit('Submit Registration', array('name'=>'submit1b'));
echo $html->submit('Register Player using Registration Credits', array('name'=>'submit2', 'id'=>'submitregistrationusingcredits')); // this will use the credits of the team

现在在您即将到来的页面上,您可以查看是否使用以下代码单击了第一个按钮:

if ( isset($_REQUEST['submit1a']) ) ... // some code
// or, if the first button has the second possibility
if ( isset($_REQUEST['submit1b']) ) ... // some code

要查看是否单击了第二个按钮:

if ( isset($_REQUEST['submit2']) ) ... // some code
于 2012-08-17T19:56:06.970 回答
1

我对 CakePHP 的 HTMl 或 Form Helper(或您在那里使用的任何东西)并不十分熟悉。但是我认为如果您在第二个数组参数中添加一个名称参数:

$html->submit('Register Player using Registration Credits', array('name' => 'usingCredits', 'id' => 'submitregistrationusingcredits'));

对两个提交按钮都这样做。然后,当您处理该请求时,您可以编写一些如下所示的代码:

if (isset($_POST['usingCredits'])) 
{
    // handle submission using credits
} 
else
{
    // handle another submission method
}

您可能希望为两者指定一个名称并检查是否设置了每个名称。但这就是想法。

于 2012-08-17T19:58:43.357 回答