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]


3 Posts   1109 Views


23 January 2009 at 6:18pm (Last edited: 23 January 2009 11:17pm), Community Member, 36 Posts

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) {

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


23 January 2009 at 11:17pm (Last edited: 23 January 2009 11:17pm), Community Member, 36 Posts

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");

And an extra function in my Page_Controller does the trick.

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

Hope this helps!!!!!


17 December 2009 at 2:06am Forum Moderator, 435 Posts

Page_Controller of a special page?