【问题标题】:Big red cancel button on a cakephp formcakephp 表单上的大红色取消按钮
【发布时间】:2014-06-02 17:07:27
【问题描述】:

有一个普通的表格:

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

... 以

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

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

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

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

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

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    据我所知,没有一种纯粹的 Cake 方法可以创建这样一个按钮。我认为最简单的方法是使用 Form helper 的 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();
    

    【讨论】:

      【解决方案2】:

      你可以像这样添加一个按钮:

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

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

      $this->表单->按钮( '点击我', 大批() ) );

      为此,您需要删除$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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-03-28
          • 2017-11-21
          • 1970-01-01
          • 1970-01-01
          • 2014-02-03
          • 1970-01-01
          • 1970-01-01
          • 2011-02-16
          相关资源
          最近更新 更多