2014-04-18 19 views
2

上有一個表單與正常:大紅色的取消按鈕一CakePHP的形式

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

... 重圓在

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

我要新增一個取消按鈕即可。

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

這產生一個鏈接,但我想要一個按鈕。

有沒有一個Cake的方法來完成這件事?

回答

3

有沒有純粹的蛋糕的方法來創建這樣一個按鈕,我知道的。我認爲使用Form幫助器的button()方法是最簡單的,向Cancel(取消)按鈕添加一個單擊事件,並在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(); 
0

可以添加一個按鈕這樣的:

$這 - >形式 - >輸入( 「」,陣列( 「類型」=> 「鍵」, 「姓名」=> 「取消」) );

您可以在第二個參數輸入中的數組中添加任何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

0

爲此,您可以使用引導按鈕類「btn btn-danger」。

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