具有各种表单的页面中存在重复的 Zend_Form 元素 ID
我如何告诉 Zend_Form 我想要一个元素(及其 ID 标签等)使用另一个 ID 值而不是元素的名称?
我在一个页面中有几个表格。其中一些有重复的名字。因此,当 Zend_Form 使用名称创建元素的 ID 时,我最终会得到多个具有相同 ID 的元素,这使得我的 (X)HTML 文档无效。
考虑到我确实必须坚持使用相同的元素名称(它们是所有表单通用的哈希,并且使用 Zend_Form 哈希元素确实是毫无疑问的),那么解决此问题的最佳解决方案是什么?
How do I tell the Zend_Form that I want an element (and it's ID-label, etc) to use another ID value instead of the element's name?
I have several forms in a page. Some of them have repeated names. So as Zend_Form creates elements' IDs using names I end up with multiple elements with the same ID, which makes my (X)HTML document invalid.
What is the best solution to fix this, given that I really have to stick with using the same element names (they are a hash common to all forms and using the Zend_Form Hash Element is really out of question)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Zend_Form_Element
有一个名为 setAttribs 的方法,它接受一个数组。您可以执行类似$element->setAttribs(array('id' => "some_id"));
的操作,或者您可以执行 $element->setAttrib('id' , 'some_id');
Zend_Form_Element
has a method called setAttribs that takes an array. You may be able to do something like$element->setAttribs(array('id' => "some_id"));
or you can do $element->setAttrib('id', 'some_id');
谢谢克里斯·古铁雷斯。
然而,正如我所说,我需要使用默认装饰器生成的 ID,例如 -label。然而,使用 $element->setAttribs() 这是不可能的。
因此基于 http://framework.zend.com/issues/browse/ZF-7125 我刚刚做了以下事情:
$element->clearDecorators();
$element->setAttrib('id', 'some_id');
$element->addDecorator("ViewHelper");
无论谁看到这个:请注意这足以满足我的需要。但可能不适合你(默认设置不仅仅是 viewHelper 装饰器)。
Thanks, Chris Gutierrez.
However, as I said, I needed to get ride of the default decorator generated IDs like -label. Wiht the $element->setAttribs() it is not possible, however.
So based on http://framework.zend.com/issues/browse/ZF-7125 I just did the following:
$element->clearDecorators();
$element->setAttrib('id', 'some_id');
$element->addDecorator("ViewHelper");
Whoever sees this: please note this was enough for what I needed. But may not be for you (the default settings has more than the viewHelper decorator).