ZF Datagrid编辑表单验证失败的原因是Ignored元素

时间:2012-08-22 14:12:30

标签: php zend-framework zfdatagrid

我有实体的编辑表格。有元素

          $feedback = new FeedbackViewer('Feedback');
    $feedback->setLabel('Feedback')->setRequired(false);
    $feedback->setPostId($this->testimonialId);
    $feedback->setAppId($this->config->testimonials->appId);
    $feedback->setIgnore(true);
    $this->addElement($feedback);

此反馈查看器使用另一个zf数据网格加载iframe,该数据网格显示表单内的反馈。 我在ZF datagrid中使用此表单

$entityId = $this->getRequest()->getParam('edit');
        if ($entityId) {
            $entityForm = call_user_func($formCallback, $entityId);
            $form->setUsePreDefinedFormElements(true);
            $form->setForm($entityForm);
        }

但是保存操作后的ZF数据网格会触发错误验证失败。删除feedbacks元素可以正确保存。 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

 $grid->setForm($form);
                if($action != 'show') {
                $form->getForm()->getElement('form_reset')->setLabel(null);
                $form->getForm()->getElement('form_submit')->setLabel(null);

                $gridParam = $this->getRequest()->getParam('grid');
                $startParam = $this->getRequest()->getParam('start');


                if ($gridParam) {
                        if ($gridParam == 'all') {
                                $gridParam = 'index';
                        }

                        // Attach to event listener custom redirect action
                        $grid->listenEvent('crud.after_update', array($this, 'setGridRedirectCallback'), array('action' => $gridParam, 'page' => $startParam));
                        $grid->listenEvent('crud.after_delete', array($this, 'setGridRedirectCallback'), array('action' => $gridParam));
                        $form->getForm()->getElement('form_reset')->setAttribs(array('onclick' => 'window.location.href = "/admin/' . $gridParam . (($startParam) ? '/start/' . $startParam : '') . '";'));
                }

我解决了这个问题,把它放在If标签中,找不到更好的解决方案。