我想使用 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 表单来做到这一点?