【发布时间】:2022-01-18 14:09:18
【问题描述】:
我的自定义 PageController 中有一个表单。
表单在模板 Register.ss 中正确呈现。
在我的设置中,PageController 上的提交功能不起作用。
我已经尝试过了,没有在 routes.yml 中设置提交路由 导致 404。
我尝试在 routes.yml 中设置提交路由 并在 $url_handlers 中导致错误:
未捕获的 ArgumentCountError:参数太少而无法运行 TherapyRegisterController::submit(), 1 传入 /var/home/xxxxx/vendor/silverstripe/framework/src/Control/RequestHandler.php 在第 323 行,预计正好是 2 个
如何让提交功能工作?
//路线:
SilverStripe\Control\Director:
rules:
therapy//anmeldung/$ID: TherapyRegisterController
# therapy//submit: TherapyRegisterController
治疗注册控制器:
类 TherapyRegisterController 扩展 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'));
}
注册.ss:
$registerForm($ID)
【问题讨论】:
标签: forms submit silverstripe