Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Problem With Creating Custom Form

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

Page: 1
Go to End
Author Topic: 553 Views
  • cachobong
    Avatar
    Community Member
    9 Posts

    Problem With Creating Custom Form Link to this post

    I created this custom form and put it in mysite/code and named it NewRegistrationForm.php

    class NewRegistrationForm extends Form {

    public function __construct($controller, $name) {
    $fields = new FieldList(
    EmailField::create("Email"),
    PasswordField::create("Password")
    );
    $actions = new FieldList(FormAction::create("login")->setTitle("Log in"));

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

    public function login(array $data, Form $form) {
    // Do something with $data
    Controller::curr()->redirectBack();
    }

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

    When i did a ?flush=1, it did not flush properly and displayed this PHP error:
    Fatal error: Class 'FieldList' not found in <omitted full path here>mysite/code/NewRegistrationForm.php on line 6

    Am i missing something?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Problem With Creating Custom Form Link to this post

    Are you on 3.0? FieldList was introduced in 3.0.

  • cachobong
    Avatar
    Community Member
    9 Posts

    Re: Problem With Creating Custom Form Link to this post

    I'm using 2.4.5

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Problem With Creating Custom Form Link to this post

    Then make sure you read documentation for 2.4 and use 2.4 supported modules. Your NewRegistrationForm class has mostly 3.0 related code so that will need to be changed to something like

    public function __construct($controller, $name) {
    $fields = new FieldSet(
    new EmailField("Email"),
    new PasswordField("Password")
    );
    $actions = new FieldSet(new FormAction('login', 'Login'));

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

    Though I wonder why you're creating a custom login form? You should use MemberAuthenicator and MemberLoginForm for handling security authentication as this will do all the work for you. Both of those classes can be altered via Object::useCustomClass() if you need to customize.

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