0

我想使用 zend 表单基于数据库打印相同的表单。

假设 db 上有 3 个人,同一张表格应打印 3 次,并带有 db 中的预加载值。我怎样才能做到这一点?

我有以下代码:

在我的类表单函数getform中:

$form = new Zend_Form();
    $form->setAction("javascript:void(0)");

    include "Form/myElements.php";
    $personElements = new Elements();

    // Create fullname Field
    $form->addElement($personElements->getMustHaveValueTextField("name", "name* :"));
    // Create school Field
    $form->addElement($personElements->getMustHaveValueTextField("school", "school* :"));
    // Create save and remove button
    $submit = $personElements->getSubmitNoDecorators("save");
    $remove = $personElements->getSubmitNoDecorators("remove");
    $form->addElements(array($submit, $remove));

    return $form;

控制器:

    $people = $db->people();
    $this->view->people = $people;

    include "Form/form.php";
    $form = new form();
    $this->view->form = $form->getform();

在我看来如下:

$i=1;
foreach($this->people as $person)
{
    // data to populate
    $data = array(
        "name" => $person['name'],
        "school" => $person['school']
        );
    $this->form->setName("formPerson".$i);
    $this->form->populate($data);
    echo $this->form;
    $i++;
    }

它仅填充最后一个表单的值。

那么我实际上如何使用 zend 表单来做到这一点?

4

1 回答 1

0

你有没有尝试过 :

$form->reset();

在你的循环内,每次渲染后

于 2013-08-12T08:55:08.270 回答