Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

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


Reply


3 Posts   1187 Views

Avatar
Piklets

Community Member, 36 Posts

23 January 2009 at 6:18pm

Edited: 23/01/2009 11:17pm

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

Avatar
Piklets

Community Member, 36 Posts

23 January 2009 at 11:17pm

Edited: 23/01/2009 11:17pm

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!!!!!

Avatar
biapar

Forum Moderator, 435 Posts

17 December 2009 at 2:06am

Page_Controller of a special page?