I have a Form in my custom PageController.
The Form renders properly in template Register.ss.
In my setup the submit - function on PageController doesn't work.
I have tried it without setting the submit-route in routes.yml resulting in a 404.
I have tried to set the submit-route in routes.yml and in $url_handlers which results in an error:
Uncaught ArgumentCountError: Too few arguments to function TherapyRegisterController::submit(), 1 passed in /var/home/xxxxx/vendor/silverstripe/framework/src/Control/RequestHandler.php on line 323 and exactly 2 expected
How to get the submit - function to work?
//routes:
SilverStripe\Control\Director:
rules:
therapy//anmeldung/$ID: TherapyRegisterController
# therapy//submit: TherapyRegisterController
TherapyRegisterController:
class TherapyRegisterController extends PageController{
private static $allowed_actions = ['registerForm', 'submit'];
private static $url_handlers = [
'anmeldung/$ID' => 'index',
//'anmeldung/submit' => 'submit',
];
public function registerForm($id)
{
$fields = new FieldList(
TextField::create('Name', 'Name')
);
$actions = new FieldList( [
$cancelButton = FormAction::create('cancel')->setTitle('ABBRECHEN')->setAttribute('formaction', 'therapy/cancel'), // 'cancel'
$sendButton = FormAction::create('submit')->setTitle('ANMELDEN')->setAttribute('formaction', 'therapy/submit') // 'submit'
]);
$validator = new RequiredFields('');
$form = new Form($this, 'registerForm', $fields, $actions, $validator);
$form->setTemplate('Register');
return $form;
}
public function submit($data, Form $form)
{
Debug::show($data);
}
public function index(HTTPRequest $request)
{
$arrayData = array (
'ID' => $request->param('ID')
);
return $this->customise($arrayData)->renderWith(array('Anmeldung', 'Page'));
}
Register.ss :
$registerForm($ID)