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";
}
}
?>