I want to apply styles to the textfield of the form but i m not getting it.does some1 can help me??
I have followed this link also but didn't get.http://doc.silverstripe.org/doku.php?id=form#using_a_custom_template
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
in you includes/yourFormname.ss
you have total control over this template.
if you dont mind please explain how you would want it done and how ad where you want to do this, a sample code may help.
tx
I followed this link http://doc.silverstripe.org/doku.php?id=form#using_a_custom_template
I kept this code in mysite/code/ HomePage.php class MyForm extends Form {
function __construct($controller, $name) {
$fields = new FieldSet(
new TextField('FirstName', 'First name'),
new EmailField('Email', 'Email address')
);
$actions = new FieldSet(
new FormAction('submit', 'Submit')
);
parent::__construct($controller, $name, $fields, $actions);
}
function forTemplate() {
return $this->renderWith(array(
$this->class,
'Form'
));
}
function submit($data, $form) {
// do stuff here
}
}
after that I kept following code in layout/HomePage.ss
I m very new to the SilverSrtipe may be my question will be very silly but i wud be thankful if u cud help me.
<form $FormAttributes>
<% 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 %>
<fieldset>
<div id="FirstName" class="field text">
<label class="left" for="$FormName_FirstName">First name</label>
$dataFieldByName(FirstName)
</div>
<div id="Email" class="field email">
<label class="left" for="$FormName_Email">Email</label>
$dataFieldByName(Email)
</div>
$dataFieldByName(SecurityID)
</fieldset>
<% if Actions %>
<div class="Actions">
<% control Actions %>$Field<% end_control %>
</div>
<% end_if %>
</form>
layout/homepage.ss should contain
$Content
$MyForm
and in your includes that is were you dump your FORM tempate. in this case MyForm.ss
Now to initialize your form you need this function inside the controller class like
class HomePage_Controller extends Page_Controller {
public function MyForm()
{
return new MyForm($this,'MyForm');
}
Hi
If you are using SS 2.4 you can use setTemplate('yourTemplate'), default template is Form.ss
Now is you just want to change style, you can include an extra css with the style for the TextField. This is easier because you don't need to create a new template.
your form:
$fields = new FieldSet(
new TextField('yourName', 'Your Name:'),
new TextField("yourSurname","Your Surname")
);
$actions = new FieldSet(
new FormAction('MyName', 'name')
);
$form = new Form($this, 'CoolForm', $fields, $actions);
return $form;
your css for 'yourName' textField:
#Form_CoolForm_yourName { font-size: 16px; blabla... }