Css Silverstripe在模板上提供更好的表单外观
我有一个客户在photoshop上设计的模板。我的审问。。。当我看到模板是:我可以把两个字段并排吗?我想把f_名字和f_姓氏放在一行。。。是否可以在类中插入标记或代码段,例如ex:div=“column1of2”$field\u这里close div为两个字段插入两列 实际上,代码生成的每个字段都位于单独的行上。那不太漂亮。可能吗 我有以下代码:Css Silverstripe在模板上提供更好的表单外观,css,forms,styles,customization,silverstripe,Css,Forms,Styles,Customization,Silverstripe,我有一个客户在photoshop上设计的模板。我的审问。。。当我看到模板是:我可以把两个字段并排吗?我想把f_名字和f_姓氏放在一行。。。是否可以在类中插入标记或代码段,例如ex:div=“column1of2”$field\u这里close div为两个字段插入两列 实际上,代码生成的每个字段都位于单独的行上。那不太漂亮。可能吗 我有以下代码: private static $allowed_actions = array( 'FormInfolettre' ); public fu
private static $allowed_actions = array(
'FormInfolettre'
);
public function FormInfolettre() {
$fields = new FieldList(
EmailField::create('f_email', 'Votre courriel'),
TextField::create('f_firstname', 'Votre prénom'),
TextField::create('f_lastname', 'Votre nom'),
TextField::create('f_message', 'Votremessage'),
);
$actions = new FieldList(
FormAction::create("Soumettre")->setTitle("Soumettre")
);
$required = new RequiredFields(
array(
'f_email',
'f_firstname',
'f_lastname',
'f_message',
));
$form = new Form($this, 'FormInfolettre', $fields, $actions, $required);
return $form;
}
我相信在新版本中,可以通过将字段添加到组中,然后为这些类添加类和CSS,一个组是左对齐的,另一个是右对齐的 或者,为了实现这一点,我在不久前推出了旧版本的Userforms。 您可以为container div等创建
我一直喜欢在表单中使用SilverStripe模板。为此,我们需要使用forTemplate函数来定义模板。使用下面的代码,我们将模板名称设置为MyForm
<?php
class MyForm extends Form {
function __construct($controller, $name) {
...
}
function forTemplate() {
return $this->renderWith(array(
$this->class
));
}
}
嗨@Gavin Bruce,对我这样的新手来说,这似乎很复杂。我理解MyForm.ss是一个模板,但是,函数构造下的三个点中的代码是什么?我很好奇你的密码这3个点只是表示缺少代码。在这里,您可以创建表单中的字段以及所需的任何其他位。是的,我知道这一点。我问你是否有一个表单函数的例子要放在函数_构造下。如果你只想使用另一个模板来创建表单,就不需要子类。如果表单中有自定义行为,则可以使用子类进行设置。@newbiesprogrammer感谢您修复了我答案中的一个错误;)没问题!你帮我我会帮你的;)
<?php
class MyForm extends Form {
function __construct($controller, $name) {
...
}
function forTemplate() {
return $this->renderWith(array(
$this->class
));
}
}
<form $FormAttributes>
<% loop $Fields %>
<% if $Message %><p style="color:red; padding: 0 0 3px 0; margin:0">$Message</p><% end_if %>
<% end_loop %>
<% if $Message %>
<p id="{$FormName}_error" class="message $MessageType">$Message</p>
<% else %>
<p id="{$FormName}_error" class="message $MessageType" style="display: none"></p>
<% end_if %>
$Fields.FieldByName(SecurityID)
<div class="row">
<div class="large-6 medium-6 small-12 columns">
$Fields.FieldByName(FirstName)
<small class="error">Please enter your first name</small>
</div>
<div class="large-6 medium-6 small-12 columns">
$Fields.FieldByName(Surname)
<small class="error">Please enter your surname</small>
</div>
</div>
<div class="typographyr">
<button class="button">Submit</button>
</div>
</form>