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

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   3811 Views

Avatar
sunita

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.http://doc.silverstripe.org/doku.php?id=form#using_a_custom_template

Avatar
patjnr

Community Member, 102 Posts

4 February 2010 at 9:37pm

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

Avatar
sunita

Community Member, 2 Posts

4 February 2010 at 10:12pm

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>

Avatar
patjnr

Community Member, 102 Posts

4 February 2010 at 10:22pm

Edited: 04/02/2010 10:22pm

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

 

Avatar
carlos

Community Member, 42 Posts

5 February 2010 at 3:15pm

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