I've just started to use the getFrontendFields method on the frontend of my sites, and it really increases time when setting up an add form like this:
function AddEventForm(){
$fields = singleton('MemberEventDo')->getFrontendFields();
$actions = new FieldSet(
new FormAction('doAddEvent', 'Tilføj Aftale')
);
$validator = NULL;
$form = new Form(
$this,
'AddEventForm',
$fields,
$actions,
$validator
);
return $form;
}
Now I'm wondering (as I'd like to do the same with an edit form), how to fill the generated form with the DataObject's fields. For me the obvioius would be the following (which unfortunately leaves me with an empty form):
function EditEventForm(){
$eventID = (int) Director::urlParam("ID");
$event = DataObject::get_by_id('MemberEventDo',$eventID);
echo $event->Title; //just for checking that I'm actually having loaded a DataObject
$fields = $event->getCMSFields($event);
$actions = new FieldSet(
new FormAction('doEditEvent', 'Redigér Aftale')
);
$validator = NULL;
$form = new Form(
$this,
'EditEventForm',
$fields,
$actions,
$validator
);
return $form;
}