Jump to:

23487 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Custom Form not working!! [solved, talking to myself]

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: 1099 Views
  • Piklets
    Avatar
    Community Member
    36 Posts

    Custom Form not working!! [solved, talking to myself] Link to this post

    Hey everyone!

    This is my custom form:

    class PatientFormMC01 extends Form {
    function __construct($controller, $name) {
    $fields = new FieldSet(
    new TextField("Field1", "Field 1"),
    new TextField("Field2", "Field 2")
    );
    $actions = new FieldSet(
    new FormAction("doForm", "Submit")
    );
    $validator = new RequiredFields(
    "Field1", "Field2"
    );
    parent::__construct($controller, $name, $fields, $actions, $validator);
    }

    function doForm($data, $form) {
    //
    Director::redirectBack();
    }
    }

    And I call it using:

    function Form(){.....
    return new PatientFormMC01($this, "Form");
    .....
    }

    But I am getting:
    Fatal error: Call to a member function loadDataFrom() on a non-object in ...sapphire/core/control/Controller.php on line 178

    Using SS 2.2.3

  • Piklets
    Avatar
    Community Member
    36 Posts

    Re: Custom Form not working!! [solved, talking to myself] Link to this post

    I don't know how this crazy part of SilverStripe works!! It was quite funny (although frustrating) finding a solution to the problem.

    SilverStripe seemed to want to find a 'return new CustomForm(...' in my Page_Controller's Form() function.
    This didn't work as the urlParam["Action"] which returned the wanted form, was lost in the process of submitting the form.

    I stumbled after a few million stumbles onto a working (but possibly dodgy) fix:

    The explained background to my problem in Form()

    $action = (int)$this->urlParams['Action'];
    switch($action) {
    case "1":
    return new CustomFormMC01($this, "CustomFormMC01");
    break;

    And an extra function in my Page_Controller does the trick.

    function CustomFormMC01() {
    return new CustomFormMC01($this, "CustomFormMC01");
    }

    Hope this helps!!!!!

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: Custom Form not working!! [solved, talking to myself] Link to this post

    Page_Controller of a special page?

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