我想使用zend表单基于数据库打印相同的表单。
假设db上有3个人,同一个表单应该从db预打载值打印3次。我怎么能这样做?
我有以下代码:
在我的课程表格函数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表单来实现呢?
答案 0 :(得分:0)
你试过了吗?
$form->reset();
每次渲染后在循环内部