Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Losing ID in my form

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

Page: 1
Go to End
Author Topic: 914 Views
  • Harley
    Avatar
    Community Member
    153 Posts

    Losing ID in my form Link to this post

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

    914 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.