在cakephp形式的大红色取消按钮

时间:2014-04-18 07:54:30

标签: cakephp

有一个正常的表格:

$this->Form->create('Users');
$this->Form->input('name');

...

结尾
$this->Form->end('Submit');

我想在它旁边添加一个取消按钮。

$this->Html->link('Cancel', array('controller' => 'users', 'action' => 'index'))

这会生成一个链接,但我想要一个按钮。

有没有Cake PHP方法来完成这项工作?

3 个答案:

答案 0 :(得分:4)

没有纯粹的Cake方式来创建我所知道的这样一个按钮。我认为最简单的方法是使用Form帮助器的button()方法,在Cancel按钮中添加一个click事件,然后在end()方法中不使用任何参数结束表单。

$this->Form->create('Users');
echo $this->Form->input('name');
echo $this->Form->button('Submit');
echo $this->Form->button('Cancel', array(
   'type' => 'button',
   'onclick' => 'location.href=\'/users\''
));
echo $this->Form->end();

答案 1 :(得分:0)

您可以添加如下按钮:

  

$ this-> Form-> input(“”,array(“type”=>“button”,“name”=>“Cancel”));

您可以在第二个输入参数中添加任何html按钮属性。

  

$这 - >形状配合>按钮(       '点击我',       阵列()       )   );

为此您需要删除$this->Form->end('Submit');而不是使用此功能:

$this->Form->submit('Submit'); //the submit button
// put the button code i mentioned above
$this->Form->end(); // and then for closing form tag

See This link for more detail

答案 2 :(得分:0)

您可以为此目的使用“btn btn-danger”引导按钮类。

echo $this->Form->button('Cancel', array(
   'type' => 'button',
   'class' => 'btn btn-danger',
   'onclick' => 'location.href=\'/users\''
));
相关问题