Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

Editing DataObject in the frontend

$
0
0

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


Posted to: Editing DataObject in the frontend | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles