Hi struggle atm with a form which is implemented on the frontend. I want to save the formdata in an enquiry object which has a many_many relation to my groups object. And in return the groups object has as belongs_many_many relation to the enquiry object. So far so good. Now i create the form for the frontend and run into an issue with the Listboxfield. I cant get it to save the selected groups. How can i do that ??
so my controller looks like that
class EnquiryPage_Controller extends Page_Controller {
function EnquiryForm() {
$groups = DataObject::get("GroupHolder",""); // getting all pages for the groups
$map = $groups->toDropDownMap();
$fields = new FieldSet(
new TextField('Title'),
new TextField('Text'),
new ListboxField('Groups','Groups',$map,$map[0],5,true)
);
// Create actions
$actions = new FieldSet(
new FormAction('doForm', 'Submit')
);
$validator = new RequiredFields('Title', 'Text');
return new Form($this, 'EnquiryForm', $fields, $actions, $validator);
}
function doForm($data, $form) {
$submission = new EnquiryObject();
$form->saveInto($submission);
$submission->write();
Director::redirectBack();
}
}
Would be awesome if someone could help me with my issue.