php - Zend Framework - 在 dl 中包装 dt dd

标签 php zend-framework

来自 Change HTML output of Zend_Form 中的另一个问题有谁知道我如何生成以下 html 输出? (用 dl 包装每个 dtdd 集)

<form>
<fieldset>
   <dl>
      <dt>label etc</dt>
      <dd>input etc</dd>
   </dl>
   <dl>
      <dt>label etc</dt>
      <dd>input etc</dd>
   </dl>
</fieldset>
... etc
</form>

最佳答案

给你:

class Default_Form_Chip extends Zend_Form
{

    protected $_element_decorators = array(
        'ViewHelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'form_element')),
        array('Label', array('tag' => 'dt', 'class' => 'required', 'tagClass' => 'form_label')),
        array('HtmlTag', array('tag' => 'dl', 'class' => 'form_wrapper')),
    );

    //put your code here
    public function init()
    {
        $this->setElementDecorators($this->_element_decorators);
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'fieldset')),
            'Form',
        ));
        $this->addElement('text', 'username',array(
            'label'=>'Username'
        ));
        $this->addElement('text', 'password',array(
            'label'=>'Password'
        ));
    }

}

输出 html:

<form enctype="application/x-www-form-urlencoded" action="" method="post">
    <fieldset>
        <dl class="form_wrapper">
            <dt id="username-label">Username</dt>
            <dd class="form_element">
                <input type="text" name="username" id="username" value="">
            </dd>
        </dl>
        <dl class="form_wrapper">
            <dt id="password-label">Password</dt>
            <dd class="form_element">
                <input type="text" name="password" id="password" value="">
            </dd>
        </dl>
    </fieldset>
</form>

关于php - Zend Framework - 在 dl 中包装 dt dd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7620082/

相关文章:

php - 使用 zend gdata 插件上传文档

php - 用 PHP 合并两个大的 CSV 文件

php - 特定查询语法在 php mysqli 中无效,但在 MySQL CLI 中无效。

php - PHP 中如何计算路径 - 为什么当前目录中的文件被忽略?

php - 搜索引擎优化 : what to do after url re writing

php - 将标签设置为由 zend 框架中的 createElement 方法创建的元素

php - Zend_Paginator 模糊 MVC 行

php - Zend Framework 1.11 与 Doctrine 2 和命名空间

php - 检查给定主键的数据库行对象是否存在?

php - 从 PHP 进行 MySQL 查找?