21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1572 Views |
-
how to apply style to the form?

4 February 2010 at 6:20pm Last edited: 4 February 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 -
Re: how to apply style to the form?

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
-
Re: how to apply style to the form?

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> -
Re: how to apply style to the form?

4 February 2010 at 10:22pm Last edited: 4 February 2010 10:22pm
layout/homepage.ss should contain
$Content
$MyFormand 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');
} -
Re: how to apply style to the form?

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... }
| 1572 Views | ||
|
Page:
1
|
Go to Top |


