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.