1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 695 Views |
-
Form creation works only if I do it against all examples

17 May 2010 at 8:21am Last edited: 17 May 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
Example2Nothing. 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?
| 695 Views | ||
|
Page:
1
|
Go to Top |

