Jump to:

23453 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Editing a multiform table

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

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

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

    Editing a multiform table Link to this post

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

    ?>

    622 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.