Zend 框架表单哈希不起作用

发布于 2024-12-20 15:25:31 字数 483 浏览 3 评论 0原文

我有一个简单的 ZF 表单,其中包含一个哈希元素:

$hash = new Zend_Form_Element_Hash('hash');
        $hash->setSalt('hf823hflw03j');
        $hash->addErrorMessage('Form must not be resubmitted');

这工作正常,但如果我选择删除所有装饰器并使用以下格式格式化表单:

$this->setDecorators( array( array('ViewScript', array('viewScript' => '_form_register.phtml'))));

那么似乎哈希值在每次提交时都会更新,因此不会'不工作。

此外,PHPunit 认为表单元素哈希无效,因此不测试表单处理。

有什么办法解决这个问题吗?

I have a simple ZF form that includes a hash element:

$hash = new Zend_Form_Element_Hash('hash');
        $hash->setSalt('hf823hflw03j');
        $hash->addErrorMessage('Form must not be resubmitted');

This works ok, but if I choose to strip out all the decorators and format the form using :

$this->setDecorators( array( array('ViewScript', array('viewScript' => '_form_register.phtml'))));

Then it seems that the hash value is renewed each time it is submitted and thus doesn't work.

In addition, PHPunit thinks the form element hash is invalid and so doesn't test the form processing.

Is there any solution to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萝莉病 2024-12-27 15:25:31

你真的需要使用 viewScript Decorator 吗?否则尝试使用它:

$this->setDecorators(array('ViewHelper','Errors'));

如果您想更改错误的外观,您可以创建自己的 ErrorDecorator,然后按如下方式使用它:

$this->setDecorators(array('ViewHelper', new My_ErrorDecorator()));

Do you really need to use viewScript Decorator? Otherwise try to use this:

$this->setDecorators(array('ViewHelper','Errors'));

If you want to change the look of the Errors, you could create your own ErrorDecorator and then use it as follows:

$this->setDecorators(array('ViewHelper', new My_ErrorDecorator()));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文