Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Editing a multiform table


Go to End


912 Views

Avatar
Harley

Community Member, 165 Posts

9 April 2010 at 1:04pm

Hello,

Could anyone shed some light on this maybe? I have a multiform on a site I've built which now needs the functionality to edit those entries via the front end. Before you ask, security is not a primary issue here as this is an application used on an intranet.

Below I have posted my code, I have so far managed to display my data rows in a table with links to 'view full details' and 'edit details'. When I edit, a form displays, but when I hit submit the page goes blank and in the URL I am getting the function for the form appended to the URL.

Why is this happening?

Thanks

Note: I have only attempted to edit one of the tables for simplicity at this stage until I get this working.

<?php

class CallerDatabase extends Page{
}

class CallerDatabase_Controller extends Page_Controller{

public function getIndividualCallDetails(){

if($URLAction = Director::URLParam('Action')){

$CallEventID = Convert::raw2xml($URLAction);

if(is_numeric($CallEventID)){
return DataObject::get_by_id('CallEvent', $CallEventID);
}
}
}

public function EditCallEvent(){
$urlAction = Director::urlParam('Action');
$desiredAction = 'editcall';
if($urlAction == $desiredAction){
$fields = new FieldSet(
new TextField('CallerFirstName', 'Callers first name')
new TextField('CallerSurname', 'Callers Surname')
new TextField('CallerFirstAge', 'Callers age')
);

$actions = new FieldSet(
new FormAction("UpdateCallEvent", "Update")
);

return new Form($this, "EditCallEvent", $fields, $actions);
}
}

public function UpdateCallEvent($data, $form){

if($urlAction == $desiredAction){

if($urlID = Director::urlParam('ID')){
$CallEventID = Convert::raw2xml($urlID);
}

$CallEvent = DataObject::get_by_id('CallEvent', $CallEventID);

if($CallEvent) {
$CallEvent->CallerFirstName = $data['CallerFirstName'];
$CallEvent->CallerSurname = $data['CallerSurname'];
$CallEvent->CallerAge = $data['CallerAge'];
$CallEvent->write();
Director::redirectBack();
return;
}
}
}

public function Success(){
return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";
}

}

?>