自定义提交按钮

问题描述 投票:15回答:7

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

cakephp forms button submit
7个回答
10
投票

还记得,你可以随时做旧学校

我更喜欢使用没有参数的$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->Form->input('Model.field', 'options' => array( array('type' => 'button'))); - 尤其是之前,之间,之后和类选项。您可以使用帮助程序创建具有良好灵活性的<input type="button" />元素。


32
投票

你可以使用Form助手的submit()button()方法而不是end()方法。例如:

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

别忘了关闭表格。你可以通过调用没有任何参数的end()方法来实现。

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

3
投票

您可以通过此代码创建自定义提交

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

2
投票

这就够了:

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

同样@Mike建议关闭表格

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

0
投票

或者您可以将两者结合使用:

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

0
投票

我使用我的under 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();

0
投票

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

$options = array(
    'label' => 'Update',
    'div' => array(
        'class' => 'glass-pill',
    )
);
echo $this->Form->end($options);
© www.soinside.com 2019 - 2024. All rights reserved.