Zend框架2 - 包裹表单元素导致验证失败 [英] Zend Framework 2 - Wrapped form elements cause validation to fail

查看:149
本文介绍了Zend框架2 - 包裹表单元素导致验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是其中包含的元素包裹形式。包装发生在视图描述的一样这里

I'm using a form which contains wrapped elements. The wrapping happens in the view like described here.

我的动作看起来是这样的:

My action looks like this:

 $myForm = [definition here]
 $myForm->setName('entity');
 $myForm->setWrapElements(true);

 $request = $this->getRequest();
 if ($request->isPost()) {

        $myEntity = new Entity();
        $myForm->bind($myEntity);
        $myForm->setData($request->getPost()->get('entity'));

问题:致电时 $ myForm->的isValid()这是无效的。打电话时 $ myForm-方式>的getData()后是空的。

The problem: When calling $myForm->isValid() it's invalid. When calling $myForm->getData() afterwards it's empty.

我在行动,但有或没有它,这是行不通的重复的setName setWrapElements

I repeated the setName and setWrapElements in the action but with or without it, it doesn't work.

任何想法我可能是做错了?表单定义是原封不动,适用于非包装的形式。所以我猜这个错误并不在那里。

Any ideas what I might be doing wrong? The form definition is untouched and works for non-wrapped forms. So I guess the error is not in there.

P.S: $ myForm-的制造&gt回声;的isValid()返回一个空字符串。有可能的方式来得到错误信息?表单字段都充满了我已经摆在那里,不显示任何错误的数据。

P.S.: An echo of $myForm->isValid() returns an empty string. Is there maybe a way to get the error message? The form fields are filled with the data I've put in there and don't show any errors.

推荐答案

使用以下内容:

$形式 - >的getMessages()

会给你的验证消息。

您可以转储内容或循环消息在的foreach 循环。例如:

You can dump the contents or loop the messages in a foreach loop. For example:

foreach($form->getMessages() as $msgId => $msg) {
    echo "Validation error: $msgId => $msg"
}

这篇关于Zend框架2 - 包裹表单元素导致验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆