【问题标题】:Custom Submit button自定义提交按钮
【发布时间】:2011-03-12 01:26:09
【问题描述】:

如何创建提交按钮,并在其上定义自定义标题以及自定义类样式?

【问题讨论】:

    标签: cakephp forms button submit


    【解决方案1】:

    您可以使用表单助手的submit()button() 方法来代替end() 方法。例如:

    echo $this->Form->submit(
        'Send', 
        array('class' => 'custom-class', 'title' => 'Custom Title')
    );
    

    不要忘记关闭表单。您可以通过不带任何参数调用 end() 方法来实现。

    echo $this->Form->end();
    

    【讨论】:

      【解决方案2】:

      另外请记住,你总是可以做到的老派

      我更喜欢使用不带参数的$this->Form->end( ); 并构建自己的提交按钮和标记。很简单

      <div class="buttons clearfix">
          <button type="submit" class="positive">
              <span class="icon-wrapper"><img src="path/to/tickmark.png" alt="" title="" /></span>
              Save Item
          </button>
      </div>
      

      我还会告诉您尝试使用$this-&gt;Form-&gt;input('Model.field', 'options' =&gt; array( array('type' =&gt; 'button'))); - 特别是之前、之间、之后和类选项。您可以使用该帮助程序以非常灵活的方式创建 &lt;input type="button" /&gt; 元素。

      【讨论】:

        【解决方案3】:

        这就够了:

        echo $this->Form->submit("Custom message");
        

        @Mike 也建议用

        关闭表单
        echo $this->Form->end();
        

        【讨论】:

          【解决方案4】:

          或者您可以将两者结合:

          echo $this->Form->end("Custom Message");
          

          【讨论】:

            【解决方案5】:

            您可以通过此代码创建服装提交

            echo $this->Form->submit(
                'Submit', 
                array('div' => false,'class' => 'urclass', 'title' => 'Title')
            );
            

            【讨论】:

            • 感谢分享。为你 +1
            【解决方案6】:

            我使用我在 app/webroot/img 下的图像创建了一个自定义按钮,该按钮使用内联样式来指定大小并将位置更改为中心

            $options=array('type'=>'Make secure payment', 'type'=>'image', 'style'=>'width:200px; height:80px; display:block; margin-left:auto; margin-right:auto;');
            echo $this->Form->submit('/img/axiaepaysecurebuttongray_med.png', $options);
            echo $this->Form->end();
            

            【讨论】:

              【解决方案7】:

              对于 CakePHP 2.x,你可以使用

              $options = array(
                  'label' => 'Update',
                  'div' => array(
                      'class' => 'glass-pill',
                  )
              );
              echo $this->Form->end($options);
              

              【讨论】:

                猜你喜欢
                • 2019-03-11
                • 1970-01-01
                • 1970-01-01
                • 2012-08-04
                • 2019-05-29
                • 2021-07-24
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多