Jump to:

23455 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Editing DataObject in the frontend

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: 362 Views
  • HGray
    Avatar
    Community Member
    2 Posts

    Editing DataObject in the frontend Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Editing DataObject in the frontend Link to this post

    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.

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