我正忙于使用 Zend_Form 对象。
我正在构建一个用于创建新发票的表单。
正如您在上图中看到的,它是一个表单,在页面和 HTML 代码的不同位置有几个不同的输入字段。
通常你会使用装饰器来做到这一点,但我认为这不是一个更好的情况。
插入新 HTML 的按钮会创建名称相同但末尾带有 [NUMBER] 的新输入字段(创建数组)。
我认为最好在 View 脚本中手动添加字段(伪代码:echo Zend_Form_Text_Element->toHtml();..
有人可以给我建议如何让它正常工作吗?
最佳答案
您应该使用 View 脚本装饰器。这是一个很好的link .
向下滚动到显示以下内容的部分:示例:使用 ViewScript 装饰器进行完全自定义
这是使用 View 脚本构建的示例表单:
<h4>Please register with us!</h4>
<form action="<?= $this->escape($this->form->getAction() ?>"
method="<?= $this->escape($this->form->getMethod() ?>">
<fieldset>
<legend>Demographics</legend>
<p>
Please provide us the following information so we can know more about
you.
</p>
<?= $this->form->age ?>
<?= $this->form->nationality ?>
<?= $this->form->income ?>
</fieldset>
<fieldset>
<legend>User Information</legend>
<p>
Now please tell us who you are and how to contact you.
</p>
<?= $this->form->firstname ?>
<?= $this->form->lastname ?>
<?= $this->form->email ?>
<?= $this->form->address1 ?>
<?= $this->form->address2 ?>
<?= $this->form->city ?>
<?= $this->form->state ?>
<?= $this->form->postal ?>
<?= $this->form->phone ?>
</fieldset>
<?= $this->form->submit ?>
</form>
这样你就可以完全控制表单的 html 并且不需要遭受装饰器的痛苦:D
关于php - Zend_Form高级用法(数组),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10686739/