Zend 框架中的三列表格表单
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您是否只需要添加
,或者是否需要在
< 内添加内容。 /td>
。在第一种情况下,您只需要在 Label 装饰器之后添加一个简单的 HtmlTag 装饰器:
如果您想放置某种字段描述,您应该使用 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 :
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.