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:

Form Questions /

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

Losing ID in my form


Go to End


1213 Views

Avatar
Harley

Community Member, 165 Posts

14 April 2010 at 12:55pm

Edited: 14/04/2010 12:56pm

Hi, need some help here with a form which I'm using in the front end to update a dataobject. Basically I'm getting a blank page when I submit my form, I've done some debugging and testing and it seems to be losing the id.

Any ideas where I'm going wrong anyone?

Here is my code:

<?php

class CallerDatabase extends Page{
}

class CallerDatabase_Controller extends Page_Controller{

	public function displayCallEvent(){
		$params = Director::urlParams();
		return (!isset($params['Action']));
	}

	public function displayEditCallForm(){
		$params = Director::urlParams();
		return (isset($params['Action']) && $params['Action'] == 'editcall');
	}

	public function displayIndividualCallDetails(){
		$params = Director::urlParams();
		return (isset($params['Action']) && $params['Action'] == 'viewcall');
	}

	public function CallEvent(){
		return DataObject::get("CallEvent");
	}

	public function getIndividualCallDetails(){

		if($urlID = Director::URLParam('ID')){

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

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

	public function EditCallEvent(){

		$urlAction = Director::URLParam('Action');

			$urlID = Convert::raw2sql(Director::urlParam('ID'));

		if(is_numeric($urlID)){
			$CallEvent = DataObject::get_by_id("CallEvent", Convert::raw2sql(Director::urlParam('ID')));
			$PersonDetail = DataObject::get_by_id("PersonDetail", Convert::raw2sql(Director::urlParam('ID')));
		}

		$fields = new FieldSet(
				new HiddenField('ID','ID: ', $urlID), 
				new TextField('FirstName', 'First name', $PersonDetail->FirstName), 
				new TextField('Surname', 'Surname', $PersonDetail->Surname), 
				new TextField('Age', 'Age', $PersonDetail->Age), 
			);

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

			return new Form($this, "EditCallEvent", $fields, $actions);
	}
	
	
	public function UpdateCallEvent($data, $form){

		$PersonDetail = DataObject::get_by_id('PersonDetail', Convert::raw2sql($data['ID']));

			if($PersonDetail){
				$PersonDetail->FirstName = $data['FirstName']; // sets property on object
				$PersonDetail->Surname = $data['Surname']; // sets property on object
				$PersonDetail->Age = $data['Age']; // sets property on object
				$PersonDetail->write(); // writes row to database
			}

		Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");
	}

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