php - Zend_Form高级用法(数组)

标签 php forms zend-form zend-form-element

我正忙于使用 Zend_Form 对象。

我正在构建一个用于创建新发票的表单。 Form which should be build with 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/

相关文章:

php - 使用alter table时是否需要mysql real escape?

php - 正则表达式分解驼峰式字符串 PHP

在命令行中执行但不在浏览器中执行的 Java 文件

php - 在 Symfony2 上创建多色选择框

ajax - Grails submitToRemote 验证

php - Zend multi Checkbox 元素的单个错误消息而不是多个

html - 您如何定位提交按钮的禁用状态?

javascript - 根据用户输入创建多步骤表单

php - 隐藏字段不能以 zend 形式工作

zend-framework - Zend Framework 动态添加表单字段并填充