Zend_Form 使用子表单getValues() 问题 [英] Zend_Form using subforms getValues() problem

查看:22
本文介绍了Zend_Form 使用子表单getValues() 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用子表单以及在这些表单上启用 Zend_JQuery 在 Zend Framework 1.9 中构建表单.表单本身很好,所有错误检查等都正常工作.但我遇到的问题是,当我尝试检索控制器中的值时,我只收到最后一个子表单的表单条目,例如

I am building a form in Zend Framework 1.9 using subforms as well as Zend_JQuery being enabled on those forms. The form itself is fine and all the error checking etc is working as normal. But the issue I am having is that when I'm trying to retrieve the values in my controller, I'm receiving just the form entry for the last subform e.g.

我的主表单类(速度的缩写):

My master form class (abbreviated for speed):

Master_Form extends Zend_Form
{

  public function init()
  {

    ZendX_JQuery::enableForm($this);

    $this->setAction('actioninhere')
         ...
         ->setAttrib('id', 'mainForm')

    $sub_one = new Form_One();
    $sub_one->setDecorators(... in here I add the jQuery as per the docs);
    $this->addSubForm($sub_one, 'form-one');

    $sub_two = new Form_Two();
    $sub_two->setDecorators(... in here I add the jQuery as per the docs);
    $this->addSubForm($sub_two, 'form-two');
  }

}

这样一切都在显示中正常工作,当我提交时没有填写所需的值,将返回正确的错误.但是,在我的控制器中,我有这个:

So that all works as it should in the display and when I submit without filling in the required values, the correct errors are returned. However, in my controller I have this:

class My_Controller extends Zend_Controller_Action
{
  public function createAction()
  {
    $request = $this->getRequest();
    $form = new Master_Form();

    if ($request->isPost()) {
      if ($form->isValid($request->getPost()) {

        // This is where I am having the problems
        print_r($form->getValues());

      }
    }
  }
}

当我提交它并且它通过 isValid() 时,$form->getValues() 只返回第二个子表单中的元素,而不是整个表单.

When I submit this and it gets past isValid(), the $form->getValues() is only returning the elements from the second subform, not the entire form.

推荐答案

我最近遇到了这个问题.在我看来,getValues 使用的是 array_merge,而不是 array_merge_recursive,它确实呈现为正确的结果.我提交了一个错误报告,但还没有得到任何反馈.我提交了一个错误报告(http://framework.zend.com/issues/browse/ZF-8078).也许你想投票?

I recently ran into this problem. It seems to me that getValues is using array_merge, instead of array_merge_recursive, which does render to correct results. I submitted a bug report, but have not gotten any feedback on it yet. I submitted a bug report (http://framework.zend.com/issues/browse/ZF-8078). Perhaps you want to vote on it?

这篇关于Zend_Form 使用子表单getValues() 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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