Zend_Form using subforms getValues() problem

前端 未结 4 1846
[愿得一人]
[愿得一人] 2021-01-27 01:56

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

相关标签:
4条回答
  • 2021-01-27 02:29

    I have a same problem to get value from subforms I solve it with this but not my desire one code: in controller i get value with this code that 'rolesSubform' is my subform name $this->_request->getParam ( 'rolesSubform' );

    0 讨论(0)
  • 2021-01-27 02:31

    I think that perhaps I must have been misunderstanding the way that the subforms work in Zend, and the code below helps me achieve what I wanted. None of my elements share names across subforms, but I guess this is why Zend_Form works this way.

    In my controller I now have:

    if($request->isPost()) {
      if ($form->isValid($request->getPost()) {
        $all_form_details = array();
        foreach ($form->getSubForms() as $subform) {
          $all_form_details = array_merge($all_form_details, $subform->getValues());
        }
        // Now I have one nice and tidy array to pass to my model. I know this
        // could also be seen as model logic for a skinnier controller, but
        // this is just to demonstrate it working.
        print_r($all_form_details);
      }
    }
    
    0 讨论(0)
  • 2021-01-27 02:34

    Encountered the same problem. Used post instead of getValues.

    $post = $this->getRequest()->getPost();
    

    There are times when getValues does not return the same values returned by $post. Must be a getValues() bug.

    0 讨论(0)
  • 2021-01-27 02:46

    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?

    0 讨论(0)
提交回复
热议问题