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.

General Questions /

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

Editing DataObject in the frontend


Reply


2 Posts   445 Views

Avatar
HGray

Community Member, 2 Posts

14 April 2014 at 11:07am

I'm needing help creating a form for the frontend where the user can edit a DataObject.

The website is basically a planner, so the user has a project (or projects) assigned to them. The projects are made up of 9 steps which the user works through gradually. Where I'm stuck is giving the user the ability to edit the Project dataobjects "Title" and "Description".

Here's what I have so far:

Edit project form

public function EditProjectForm() {
         
$projectID = (int) $this->request->param('ID');
   $project = Project::get()->byID($projectID);
   
   $project->ProjectID = $project->ID;
   
   $fields = new FieldList(
      TextField::create('Title', 'Project Title'),
      TextareaField::create('Description', 'Project Description'),
      FileField::create('ProjectImage', 'ProjectImage'),
      TextField::create('Category', 'Category'),
   TextField::create('ProjectID')
   );
      
   $actions = new FieldList(
      FormAction::create("doEdit", 'Submit changes')
   );
      
   $form = new Form($this, 'EditProjectForm', $fields, $actions);
   $form->loadDataFrom($project);
      
   return $form;
}

doEdit Action

public function doEdit($data, Form $form) {
      
$projectID = $data['ProjectID'];
      $project = Project::get()->byID($projectID);

$form->saveInto($project);

$project->Title = $data['Title'];
$project->Description = $data['Description'];

$project->write();

$this->redirectBack();

}

This creates the form fine, and populates the form with the projects information. But when I click doEdit it just goes to a blank white page at www.mypage.com/EditProjectForm

I'm really stuck on this, and given I'm very much a beginner to PHP this is a major headache...

Avatar
swaiba

Forum Moderator, 1799 Posts

30 April 2014 at 1:09am

The "offical" method for 2.4 is genericviews - https://github.com/chillu/silverstripe-genericviews
I Think this is mostly going to work on 3.x too.