Jump to:

23471 Posts in 18937 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » how to apply style to the form?

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

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

Page: 1
Go to End
Author Topic: 2037 Views
  • sunita
    Avatar
    Community Member
    2 Posts

    how to apply style to the form? Link to this post

    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

  • patjnr
    Avatar
    Community Member
    101 Posts

    Re: how to apply style to the form? Link to this post

    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

  • sunita
    Avatar
    Community Member
    2 Posts

    Re: how to apply style to the form? Link to this post

    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>

  • patjnr
    Avatar
    Community Member
    101 Posts

    Re: how to apply style to the form? Link to this post

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

  • carlos
    Avatar
    Community Member
    41 Posts

    Re: how to apply style to the form? Link to this post

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

    2037 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.