Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Cannot display custom 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: 820 Views
  • getmizanur
    Avatar
    Community Member
    2 Posts

    Cannot display custom form Link to this post

    elloo,

    i'm trying to create a simple custom login form however the form is not loading, all i get is a blank page. My code is listed below, can someone tell me what i'm doing wrong.

    Many thanks in advance

    ps: the form for now excepts FirstName and LastName

    class LoginPage extends Page {
    static $db = array(
    );
    static $has_one = array(
    );
    }

    class LoginPage_Controller extends Page_Controller {
    static $allowed_actions = array(
    );

    public function init() {
    parent::init();
    }

    public function FormBox() {
    return new LoginForm($this, 'LoginForm');
    }
    }

    mysite/code/LoginForm

    class LoginForm extends Form {
    function __construct($controller, $name) {
    $fields = new FieldSet(
    new TextField('FirstName', 'FirstName'),
    new TextField('LastName', 'LastName')
    );

    $actions = new FieldSet(
    new FormAction('submit', 'Submit')
    );

    parent::__construct($controller, $name, $fields, $actions);
    }

    function forTemplate() {
    return $this->renderWith(array(
    $this->class, 'LoginForm'
    ));
    }

    function submit($data, $form) {

    }
    }

    themes/blackcandy/templates/Includes/LoginForm.ss

    <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_LastName">Last Name</label>
    $dataFieldByName(LastName)
    </div>

    </fieldset>

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

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