I need froms which supplies CRUD in fronend. No problem to get it working in the backend. I just testetd GenericViews, but it just works for the action view. When i try to customize the url like this
form/8/view to
form/8/edit
i got an empty page. Silverstripe Version is 2.4.5
So i tried out how to make it by my own,
the form Page looks liek this. I tried to get the data after creation back into the form fields.
i save the ID in "createPerson" with Session::set('ID',$submission->ID);
and get it back in myForm with DataObject::get_by_id('HorseSubmission',$id);
is it the right way? How to updated data for an special ID?
class FormPage extends Page {
static $db = array(
);
static $has_one = array(
);
}
class FormPage_Controller extends Page_Controller {
function myForm() {
if(Session::get("ID"))
{
$id = Session::get("ID");
$record = DataObject::get_by_id('HorseSubmission',$id);
$fields = new FieldSet(
new TextField('Person','Person',$record->Person),
new ImageField('Image1','Bild',$record->Image1),
new ImageField('Image2','Bild',$record->Image2),
);
// Create actions
$actions = new FieldSet(
new FormAction('createHorse', 'Submit')
);
return new Form($this, 'myForm', $fields, $actions);
} //end if
else
{
$fields = new FieldSet(
new TextField('Name'),
new ImageField('Image1'),
new ImageField('Image2')
);
$actions = new FieldSet(
new FormAction('createPerson', 'Submit')
);
return new Form($this, 'myForm', $fields, $actions);
} // end else
}
function createPerson($data, $form) {
$submission = new PersonSubmission();
$form->saveInto($submission);
$submission->write();
Session::set('ID',$submission->ID);
Director::redirectBack();
}
}