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.

Form Questions /

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

Form creation works only if I do it against all examples


Go to End
Reply


995 Views

Avatar
silk

Community Member, 18 Posts

17 May 2010 at 8:21am

Edited: 17/05/2010 11:40pm

Hello,

I am using version 2.4 with nested urls.

I tried to write a form for my page:

class TippToppMatchPage extends Page{
(...)
}

class TippToppMatchPage_Controller extends Page_Controller{
(...)

// Necessary to do in 2.4:
static $allowed_actions = array(
'match' => true,
'tipp' => true,
'TippForm' => true,
'doTippForm' => true
);

public function TippForm(){

if(($URLAction = Director::URLParam('Action')) && ($URLAction == 'tipp') && ($URLID = Director::URLParam('ID'))){
$matchID = Convert::raw2xml($URLID);

if((is_numeric($matchID)) && ($match = DataObject::get_by_id('TippToppMatch', $matchID))){

$form = new Form(
$controller = $this,
$name = "TippForm",
$fields = new FieldSet(
new HiddenField($name = "MatchID", $title="MatchID", $value = $matchID),
new NumericField($name = "team1", $title=$match->Team1()->Name, $value=$match->getTippForCurrentUser()->Team1Tipp),
new NumericField($name = "team2", $title=$match->Team2()->Name, $value=$match->getTippForCurrentUser()->Team2Tipp)
),
$actions = new FieldSet(
// List the action buttons here
new FormAction("doTippForm", "Tippen")
),
$requiredFields = new RequiredFields('team1', 'team2'
// List the required fields here: "Email", "FirstName"
)
);
return $form;
}
}

function doTippForm($data){

if(($matchID = $data['MatchID']) && (is_numeric($matchID)) && ($match = DataObject::get_by_id('TippToppMatch', $matchID))){
$tipp = $match->getTippForCurrentUser();
$tipp->setField('Team1Tipp', $data['team1']);
$tipp->setField('Team2Tipp', $data['team2']);
$tipp->write();
}
Director::redirectBack();
}
}

Additionally, I created a template calling $TippForm. Everything looked fine, but calling the submit button resulted in the dreaded white screen of death.

I checked and rechecked all examples, like
Example1
Example2

Nothing. I then checked the created source code and discovered that the called action was TippForm(), not doTippForm(). Introducing a debug message print "hello world" into TippForm() confirmed that this method was called.
Changing the form creation to
$form = new Form(
$controller = $this,
$name = "doTippForm",
(...)

managed to give the result I have tried to achieve for two days of pondering.
Everything now works fine, but I am quite irritated. Have I a mistake in my original code so that introducing a second mistake seems to fix it, or did something in silverstripe rchange recently?