我在我的CakePHP 2.6应用程序中有一个表单,它有多个按钮来提交表单到不同的操作。在Cake 2.4中,这是可行的,但在2.6中,提交到任何非默认表单操作都会导致黑洞'auth'
错误。
就在我的表单结束之前,我有多个提交按钮,如下所示:
echo $this->Form->button('Default', array(
'type' => 'submit',
));
echo $this->Form->button('Alternate 1', array(
'type' => 'submit',
'formaction' => '/posts/otheraction',
));
echo $this->Form->button('Alernate 2', array(
'type' => 'submit',
'formaction' => '/posts/anotheraction',
));
Reading the docs,我看到了‘auth’ Indicates a form validation error, or a controller/action mismatch error.
。但是,这在过去是有效的-似乎事情变得更严格了。如何让Cake接受从其他操作提交的表单而不完全关闭安全性?
2条答案
按热度按时间envsm3lx1#
这似乎是不可能的(至少在没有跳过足够大的铁环的情况下是不可能的),因为动作是无条件地合并到令牌中的。
http://github.com/cakephp/cakephp/blob/2.7.1/lib/Cake/View/Helper/FormHelper.php#L589
此外,禁用此行为可能会削弱安全性,因为将数据发布到不用于的操作可能会导致意外行为。
您可以通过一个操作来处理这个问题,例如,为各个提交按钮指定一个名称和一个值,然后在控制器操作中计算该值并执行任何需要执行的操作
第一个
4bbkushb2#
我使用jQuery来更改表单的操作
HTML按钮:
浏览器: