Silverstripe Version:
3.6.2
Question:
I am having trouble finding the right way to add a form on a dataobject as page.
Details of your query go here
I have set up a basic form that I need on my pages, I have tried to add it to page and it works perfectly.
When I move the code to the DOaP(DataObject as Page) It just redirects to the controller.
I am not sure if I need to add a route to the site for that or if I am doing something wrong/
private static $allowed_actions = array(
'ChapterRegisterForm'
);
public function ChapterRegisterForm(){
$titleOptions = array(
'Prof' => 'Prof',
'Dr' => 'Dr',
'Mrs' => 'Mrs',
'Mr' => 'Mr',
'Ms' => 'Ms',
'Other' => 'Other',
);
$fields = new FieldList(
$title1 = new DropdownField('Title', 'Title', $titleOptions),
$firstname1= new TextField('FirstName', 'First Name'),
$surname1 = new TextField('Surname', 'Surname') ,
);
//Form Action
$actions = new FieldList(
new FormAction('DoSubmit', 'Register')
);
//Create form
$form = new Form($this, 'ChapterRegisterForm', $fields, $actions, $validator);
return $form;
}
public function DoSubmit($data, $form) {
$submission = EventUsers::create();
$submission->EventPageID = $this->ID;
$form->saveInto($submission);
$submission->write();
$form->sessionMessage('Thank you for registering!','good');
Controller::curr()->redirectBack();
Session::setFormMessage($form->FormName(), 'Save sucessfull', 'good');
}