Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

how to apply style to the form?

Go to End

5 Posts   3355 Views


Community Member, 2 Posts

4 February 2010 at 6:20pm

Edited: 04/02/2010 6:21pm

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.


Community Member, 102 Posts

4 February 2010 at 9:37pm

in you includes/
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.



Community Member, 2 Posts

4 February 2010 at 10:12pm

I followed this link
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(

function submit($data, $form) {
// do stuff here


after that I kept following code in layout/
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 %>

<div id="FirstName" class="field text">
<label class="left" for="$FormName_FirstName">First name</label>

<div id="Email" class="field email">
<label class="left" for="$FormName_Email">Email</label>


<% if Actions %>
<div class="Actions">
<% control Actions %>$Field<% end_control %>
<% end_if %>


Community Member, 102 Posts

4 February 2010 at 10:22pm

Edited: 04/02/2010 10:22pm

layout/ should contain


and in your includes that is were you dump your FORM tempate. in this case

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');



Community Member, 42 Posts

5 February 2010 at 3:15pm


If you are using SS 2.4 you can use setTemplate('yourTemplate'), default template is

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... }