在 CakePHP 1.3 中,您可以创建一个带有多个提交按钮的表单:
echo $this->Form->submit('Submit 1', array('name'=>'submit');
echo $this->Form->submit('Submit 2', array('name'=>'submit');
并检测在控制器中按下了哪个提交按钮:
if (isset($this->params['form']['submit']) && $this->params['form']['submit'] == "Submit 1") {
// first button clicked
}
在 CakePHP 中,$this->params['form'] 没有设置,点击的按钮值不会出现在 $this->request, $this->request->data, $this->params, $ this->data 或 $_POST。
如何确定在 CakePHP 2.0 中单击了哪个按钮?
提前致谢。
编辑:
根据要求,这是表单的代码:
<?php echo $this->Form->create('History', array('action'=>'add')); ?>
<div class='submit'>
<?php
echo $this->Form->submit('Yes', array('div'=>false, 'name'=>'submit'));
echo $this->Form->submit('No', array('div'=>false, 'name'=>'submit'));
?>
</div>
<?php echo $this->Form->end()?>
以及表单的输出:
<form action="/projects/kings_recruit/trunk/www/histories/add" id="HistoryAddForm" method="post" accept-charset="utf-8">
<div style="display:none;">
<input name="_method" value="POST" type="hidden">
</div>
<div class="submit">
<input name="submit" value="Yes" type="submit">
<input name="submit" value="No" type="submit">
</div>
</form>