21489 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 252 Views |
-
Forms which change with urlParams['ID']

12 October 2012 at 4:19pm
Hi,
I have a system which lists various dataobject, these dataobjects have a 'status' and depending on the status, the form has slightly different fields. The code is below.
The problem is that when SS submits the form, it reloads the function GetItemEditForm in the browser, and doesn't have item ID in the url, and therefore doesn't have the Status, therefore doesn't load the fields, therefore the form info used to 'saveInto' is blank...
If there any way around it? i could write a different form/save function for each status, but this would be simpler...
function GetItemEditForm () {
$id = $this->urlParams['ID'];
$CoachingItem = DataObject::get_by_id('CoachingItem', $id);
$itemStatus= $CoachingItem->Status;
if ($itemStatus== 'Define') {
$fields = new FieldSet(
new HiddenField('MemberID','', $MemberID),
new HiddenField('Status','', 'Define'),
new HiddenField('ID',''),
new TextField("Title", "My challenge"),
new TextAreaField("DefineGoal", "My goal, incl. time frames", '4', '')
);
}
if ($section == 'Plan') { $fields = new FieldSet();$validator = new RequiredFields(); }
if ($section == 'Implement') { $fields = new FieldSet();$validator = new RequiredFields(); }
if ($section == 'Review') { $fields = new FieldSet();$validator = new RequiredFields(); }
$actions = new FieldSet(new FormAction('SaveItemEditForm', 'Save') );
$form = new Form($this, "GetItemEditForm", $fields, $actions);
// load in existing content into the form
$CoachingItem = DataObject::get_by_id('CoachingItem', $id);
$form->loadDataFrom($CoachingItem);
return $form;
}
function SaveItemEditForm($data, $form) {
$item = DataObject::get_by_id('CoachingItem', $data['ID']); // loads existing item
$form->saveInto($item);
$item->write();
} -
Re: Forms which change with urlParams['ID']

15 October 2012 at 1:42pm
You need to make the form able to reload itself
Where you get the ID like this:
$id = $this->urlParams['ID'];
You can do it like this instead:
$id = empty($_REQUEST['ID']) ? $this->urlParams['ID'] : $_REQUEST['ID'];
That way one the reload the ID will be picked up from the hidden field you created.
-
Re: Forms which change with urlParams['ID']

15 October 2012 at 2:05pm
Hi Sam: thanks - that makes sense...
| 252 Views | ||
|
Page:
1
|
Go to Top |


