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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Form with DropdownField and Data Model with $many_many


Go to End


1134 Views

Avatar
Dobby

Community Member, 15 Posts

18 April 2016 at 8:43am

I have a form on a page. On this form I have a DropdownField. This Dropdown should be filled with Data, which is filtered.

This is my code

     public function SpieleForm() {
         //Debug::dump($dataToEdit); die;
         if ($this->request->param("OtherID")){
         $dataToEdit = Spiele::get()->byID($this->request->param("OtherID"));
		}

        // Felder für Formular vorbereiten
		$fields = new FieldList(
		    DateField::create("Datum", "Datum (Klicken für Kalender)")
			->setConfig( "showcalendar", true ),
			TimeField::create("Uhrzeit", "Uhrzeit"),
			DropdownField::create('StadionID', 'Stadion', Stadion::get()->map('ID', 'Name')),
			DropdownField::create("GruppeID","Gruppe", Gruppen::get()->map('ID', 'Name'))->setEmptyString('(Bitte auswählen)'),
		    DropdownField::create("HeimID","Heimteam", Teams::get()->filter(array("Saison.ID" => $this->request->param("ID")))->map('ID', 'Name')->toArray())->setEmptyString('(Bitte auswählen)'),
		    TextField::create("H1","Pkt Heim 1.Viertel"),
		    TextField::create("H2","Pkt Heim 2.Viertel"),
		    TextField::create("H3","Pkt Heim 3.Viertel"),
		    TextField::create("H4","Pkt Heim 4.Viertel"),
		    TextField::create("PktHeim","Pkt Heim Gesamt"),
		    DropdownField::create("GastID","Gastteam", Teams::get()->map('ID', 'Name')->toArray())->setEmptyString('(Bitte auswählen)'),
		    TextField::create("G1","Pkt Gast 1.Viertel"),
		    TextField::create("G2","Pkt Gast 2.Viertel"),
		    TextField::create("G3","Pkt Gast 3.Viertel"),
		    TextField::create("G4","Pkt Gast 4.Viertel"),
		    TextField::create("PktGast","Pkt Gast Gesamt"),
		    DropdownField::create("StatusID","Status", Status::get()->map()->toArray()),
		    HiddenField::create("ID","ID"),
		    HiddenField::create("SaisonID","SaisonID",$this->request->param("ID"))
            
           
        );

        $actions = new FieldList(
            FormAction::create("SpieleEintragen","Eintragen")
        );

        $form = new Form($this, 'SpieleForm', $fields, $actions);
		$form->loadDataFrom($dataToEdit);
           
		return $form;
		}
	

The Data Model Teams has $many_many with the Data Model "Saison".
I get the right teams in my dropdown, but I can't save it. A validation error occurs and says the value of the ID is not valid.
I can save the data when i change variable $this->request->param("ID") to a number. For example 1. The it works and that seems really strange.