17688 Posts in 4607 Topics by 2180 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 770 Views |
-
Custom Form not working!! [solved, talking to myself]

23 January 2009 at 6:18pm Last edited: 23 January 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 178Using SS 2.2.3
-
Re: Custom Form not working!! [solved, talking to myself]

23 January 2009 at 11:17pm Last edited: 23 January 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!!!!!
-
Re: Custom Form not working!! [solved, talking to myself]

17 December 2009 at 2:06am
Page_Controller of a special page?
| 770 Views | ||
|
Page:
1
|
Go to Top |

