Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Form creation works only if I do it against all examples

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

Page: 1
Go to End
Author Topic: 855 Views
  • silk
    Community Member
    18 Posts

    Form creation works only if I do it against all examples Link to this post


    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']);

    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

    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?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.