Php SilverStripe登录表单定制

Php SilverStripe登录表单定制,php,silverstripe,Php,Silverstripe,定制默认silverstripe登录表单的最简单方法是什么?我的最终目标是将->setExtraClass('myClass')应用于登录操作按钮。在SilverStripe 3.4中,我们可以扩展MemberLoginForm,在构造函数中设置操作,然后将SilverStripe设置为使用自定义登录类作为默认登录类 首先,我们创建一个CustomMemberLoginForm类: mysite/code/CustomMemberLoginForm.php class CustomMemberL

定制默认silverstripe登录表单的最简单方法是什么?我的最终目标是将
->setExtraClass('myClass')
应用于登录操作按钮。

在SilverStripe 3.4中,我们可以扩展
MemberLoginForm
,在构造函数中设置操作,然后将SilverStripe设置为使用自定义登录类作为默认登录类

首先,我们创建一个
CustomMemberLoginForm
类:

mysite/code/CustomMemberLoginForm.php

class CustomMemberLoginForm extends MemberLoginForm {

    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) {

        $actions = FieldList::create(
            FormAction::create('dologin', _t('Member.BUTTONLOGIN', 'Log in'))->addExtraClass('myClass'),
            LiteralField::create(
                'forgotPassword',
                '<p id="ForgotPassword"><a href="Security/lostpassword">'
                . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
            )
        );

        parent::__construct($controller, $name, $fields, $actions);
    }
}
Object::useCustomClass('MemberLoginForm', 'CustomMemberLoginForm');

一种方法是覆盖默认的
FormAction.ss
模板文件,并在其中添加类:

主题/[主题名称]/templates/forms/FormAction.ss


$ButtonContent$Title.XML

唯一的问题是
$attributestml
将添加额外的
属性,这将导致无效和不正确的html标记。在登录表单上,生成的html是
。这是一个遗憾,因为我认为如果您想将这些类添加到每个表单操作中,这是一个更好的解决方案。我知道这个答案现在已经很老了,但是您可以使用
$getAttributesHTML(“类”)
排除重复属性(排除
属性,但插入所有其他内容)。
<% if $UseButtonTag %>
    <button class="action btn medium solid" $AttributesHTML>
        <% if $ButtonContent %>$ButtonContent<% else %>$Title.XML<% end_if %>
    </button>
<% else %>
    <input class="action extra class here" $AttributesHTML />
<% end_if %>