Zend中的ViewScript装饰器丢失了Zend_Form的值

时间:2013-02-08 13:38:20

标签: zend-framework zend-form decorator zend-form-element

我使用Zend Framework 1.12。我有一些表格,它们填充了数据库中的值,默认情况下。这些值可能会被用户更改,以便在数据库中更新。

表单显示没有问题,数据库中的值被正确加载。 但是当我提交表单时,值会丢失,表单也不会提交,因为表单元素的必需值似乎是空的。

不使用装饰器,它们可以正常工作。 以下是我管理表单元素的方法。表单是“Zend_Form_Subform”,它们是Zend_Form的成员。

表格形式:

class Application_Form_People_MyForm extends Zend_Form_SubForm {
    public function init() {

    $elm = $this->createElement('text','element1');
    $elm->setLabel('Write the value here')
                ->setRequired(true);
    ...
    ...
    }
    public function loadValues() {
          $this->getElement('element1')->setValue('some value (usually sth from db)..');
}

并且,在装饰者:

<article class="somename">

    <form action="<?php echo $this->element->getAction() ?>" 
          method="<?php echo $this->element->getMethod() ?>">
        <table id="table1">
            <tr>
                <td><div id='title'><?php 
                $option = $this->element->getDecorator('ViewScript')->getOptions();
                echo $option[0]['label'] ?> </div> </td>
            </tr>


                <?php foreach ($this->element as $element) {
                    if ($element->getId() != "title") {
                         ?> <tr><td> <? echo $element; ?> </td></tr> <?
                    }

                } ?>
        </table>

    </form>
</article>

以下是我的控制器所包含的内容,以及装饰器设置

class PeopleController extends Zend_Controller_Action {

  public function indexAction() {
        .......
        $myform = new Application_Form_People_MyForm();
        $myform->loadValues();
        $myform->setDecorators(array(
                array('ViewScript', array(
                        'viewScript' => "/decorator/_somedecorator.phtml",
                    array('label' => "A TITLE FOR FORM PAGE"),
                ))
            ));
        $myform2 = .... 

        $myform3 = ....


        $generalform->addSubForm($myform, 'myform');
        $generalform->addSubForm($myform2, 'myform2');
        $request = $this->getRequest();
        if ($request->isPost()) {
               if ($generalform->isValid($request->getPost())) {
                       $myform->saveValues();
                       $myform2->saveValues();
               }
        }

        $this->view->generalform = $generalform;
 }
}

使用这个装饰器,我可以很好地设计我的元素。 只是,不能正确使用表单提交...

您认为问题是什么?提前谢谢你......

增加:

我还观察到,当用户单击其中一个提交时,用户单击的子表单已经过验证,但页面中的其他子表单会丢失值。真奇怪。我认为这可能是因为这些子表单中的某些元素名称相同,所以我更改了它们但问题仍在继续..

0 个答案:

没有答案