21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1683 Views |
-
Filling getFrontendFields with a DataObject's data

25 February 2010 at 10:10pm
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;}
-
Re: Filling getFrontendFields with a DataObject's data

5 March 2010 at 4:39am
Just got stuck on this myself, but in the admin back-end screens. This seems to work for me:
$fields->setValues($event->getAllFields());
That gets all the values from the event object into an array, and then passes them into the fields in the fieldset.
-- Jason
-
Re: Filling getFrontendFields with a DataObject's data

25 March 2010 at 9:17am
Great.
I just checked up on it, and it works! -
Re: Filling getFrontendFields with a DataObject's data

1 June 2010 at 6:35pm
$form->loadDataFrom($event);
does the same on the form, after it has been constructed.
| 1683 Views | ||
|
Page:
1
|
Go to Top |



