Zend 框架中的三列表格表单

发布于 2024-12-05 05:08:07 字数 1892 浏览 0 评论 0原文

我在 Zend Framework 中创建“三列表”表单时遇到一些问题:

我已经有由两列表装饰的 Zend Form:

表有两列,第一个用于标签,第二个用于 Zend_Form_Element,效果很好,但是, 我想添加第三列并放在那里小图像 - 问号,我将在其中设置 javascript。

该如何设置装饰呢?

两列表的当前装饰是:

<?php
class Application_Form_Login extends Zend_Form {

public function init() {

    // create decoration for form's elements
    $elementDecoration = array(
        'ViewHelper',
        'Description',
        'Errors',
        array(array('data'=>'HtmlTag'), array('tag' => 'td', 'valign' => 'TOP')),
        array('Label', array('tag' => 'td')),
        array('Errors'),
        array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
    );
    $buttonDecoration = array(
        'ViewHelper',
        array(array('data'  => 'HtmlTag'), array('tag' => 'td')),
        array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
        array(array('row'   => 'HtmlTag'), array('tag' => 'tr')),
    );
    $formDecoration = array(
        'FormElements',
        array(array('data'=>'HtmlTag'), array('tag'=>'table', 'class'=>'forms')),
        'Form'
    );

    // create form elements
    $username = new Zend_Form_Element_Text("username");
    $username->setLabel('Username: ')
             ->setDecorators($elementDecoration);

    $password = new Zend_Form_Element_Password("password");
    $password->setLabel('Password: ')
             ->setDecorators($elementDecoration);

    $submit = new Zend_Form_Element_Submit('Login');
    $submit->setLabel('LOGIN')
           ->setDecorators($buttonDecoration);

    $this->setDecorators($formDecoration);

    // set created form elements
    $this->setAction('')
        ->setMethod('post')
        ->addElement($username)
        ->addElement($password)
        ->addElement($submit);
    }

   }

I have some problem to create "three columns table" form in Zend Framework:

I already have Zend Form decorated by tow columns table:

Table have two column, first one is for label and second one is for Zend_Form_Element, that works well, but,
I want to add third column and put there small image - question mark, where I will setup javascript.

How to set decoration for that?

Current decoration for two columns table is:

<?php
class Application_Form_Login extends Zend_Form {

public function init() {

    // create decoration for form's elements
    $elementDecoration = array(
        'ViewHelper',
        'Description',
        'Errors',
        array(array('data'=>'HtmlTag'), array('tag' => 'td', 'valign' => 'TOP')),
        array('Label', array('tag' => 'td')),
        array('Errors'),
        array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
    );
    $buttonDecoration = array(
        'ViewHelper',
        array(array('data'  => 'HtmlTag'), array('tag' => 'td')),
        array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
        array(array('row'   => 'HtmlTag'), array('tag' => 'tr')),
    );
    $formDecoration = array(
        'FormElements',
        array(array('data'=>'HtmlTag'), array('tag'=>'table', 'class'=>'forms')),
        'Form'
    );

    // create form elements
    $username = new Zend_Form_Element_Text("username");
    $username->setLabel('Username: ')
             ->setDecorators($elementDecoration);

    $password = new Zend_Form_Element_Password("password");
    $password->setLabel('Password: ')
             ->setDecorators($elementDecoration);

    $submit = new Zend_Form_Element_Submit('Login');
    $submit->setLabel('LOGIN')
           ->setDecorators($buttonDecoration);

    $this->setDecorators($formDecoration);

    // set created form elements
    $this->setAction('')
        ->setMethod('post')
        ->addElement($username)
        ->addElement($password)
        ->addElement($submit);
    }

   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不念旧人 2024-12-12 05:08:07

这取决于您是否只需要添加 ,或者是否需要在 < 内添加内容。 /td>

在第一种情况下,您只需要在 Label 装饰器之后添加一个简单的 HtmlTag 装饰器:

array('HtmlTag', array('tag'=>'td','class'=>'fieldTip','placement'=> 'APPEND'))

如果您想放置某种字段描述,您应该使用 Description 装饰器和 $element->setDescription() 方法,然后执行一些 css/js,将其显示为工具提示。

编辑

我刚刚回答了有关简单自定义装饰器的另一个问题,您会在我给出的示例中找到您需要的内容使用 Javascript 的 Zend Form Element - 装饰器、视图帮助器还是视图脚本?。只需将

It depends on if you only require to add <td class="fieldTip"></td>, or if you need to add things inside the <td></td>.

In the first case you just need to add a simple HtmlTag decorator right after the Label decorator :

array('HtmlTag', array('tag'=>'td','class'=>'fieldTip','placement'=> 'APPEND'))

If you want to put some sort of description of the field you should play with the Description decorator, and the $element->setDescription() method, and do some css/js after, to display it as a tooltip.

EDIT

I just answered an other question about simple custom decorators, you'll find what you need in the example i give there Zend Form Element with Javascript - Decorator, View Helper or View Script?. Just replace the <script> part with whatever you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文