php – ZF2阻止多个表单提交

在ZF2表单中是否有任何方法可以防止多个表单提交?我已经使用isValid()函数测试了Captcha和CSRF元素,但它们不会阻止多次提交,尤其是那些使用浏览器刷新按钮的提交.
提前致谢

解决方法:

是的,有一个名为PRG的控制器插件

POST / REDIRECT / GET PLUGIN

引用官方zf2文档:

When a user sends a POST request (e.g. after submitting a form), their
browser will try to protect them from sending the POST again, breaking
the back button, causing browser warnings and pop-ups, and sometimes
reposting the form. Instead, when receiving a POST, we should store
the data in a session container and redirect the user to a GET
request.

http://framework.zend.com/manual/2.0/en/modules/zend.mvc.plugins.html#the-post-redirect-get-plugin

用我自己的话说进一步扩展;使用此插件时,每次POST提交表单时,POST变量都会存储到SESSION中,并且用户会被重定向到不同的路由或简单的相同路由(刷新).然后可以通过PRG插件访问Form变量,作为模仿原始POST数组的简单数组.这样可以防止多次发布FORM.

用法(来自ZF2文档):

// Pass in the route/url you want to redirect to after the POST
$prg = $this->prg('/user/register', true);

if ($prg instanceof \Zend\Http\PHPEnvironment\Response) {
    // returned a response to redirect us
    return $prg;
} elseif ($prg === false) {
    // this wasn't a POST request, but there were no params in the flash messenger
    // probably this is the first time the form was loaded
    return array('form' => $myForm);
}

// $prg is an array containing the POST params from the prevIoUs request
$form->setData($prg);

// ... your form processing code here

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...