多个提交按钮在cakephp形式 [英] Multiple Submit buttons in cakephp form
问题描述
我在cakephp视图中有一个表单,可以用单个按钮很好地保存,下面是视图中的代码book_form.ctp
I have a form in a cakephp view which saves well with a single button, here is the code in the view book_form.ctp
echo $this->Form->create
(
'Book',
array
(
'url' => array
(
'controller' => 'Books',
'action' => 'save_record'
),
'class' => 'span12 the_ajaxform',
'inputDefaults' => array
(
'label' => false,
'error' => false
)
)
);
.
.
// form fields
.
.
$options =array(
'label' => __('Save'),
'class' => 'btn btn-primary',
'id'=>'saveform'
);
echo $this->Form->end($options);
.
.
这完美!现在我想在表单上添加两个按钮,这是我做的
This works perfect! Now i wanted to add two buttons on that form and this is what i did
$options =array(array(
'label' => __('Save & Close'),
'class' => 'btn btn-primary',
'id'=>'saveform'
),
array(
'label' => __('Save & Create New'),
'class' => 'btn btn-primary',
'id'=>'saveformnew'
)
array(
'label' => __('Cancel'),
'class' => 'btn btn-primary',
'id'=>'formcancel'
));
echo $this->Form->end($options);
但这只会带来一个按钮,甚至不提交表单,哪里会出错?
和每个按钮可以在控制器中调用不同的方法?
提前感谢
But this only brings one button which wont even submit the form,where am i going wrong? and can each button call a different method in the controller? Thanks in advance
推荐答案
我不确定是否为技术上正确,HTML4,5兼容等等,但我一直做这样的东西,到目前为止没有任何问题:
I am not sure whether it is "Technically Correct", HTML4, 5 compatible or not etc. but I have always done it something like this, without any problem so far:
<?php echo $this->Form->submit('Delete it', array('name'=>'User[formaction]')); ?>
<?php echo $this->Form->submit('Undelete Selected', array('name'=>'User[formaction]'); ?>
<?php echo $this->Form->submit('Purge Selected', array('name'=>'User[formaction]')); ?>
其中User是型号名称。
where "User" is the model name.
这篇关于多个提交按钮在cakephp形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!