Zend Forms - Element ID modification to allow re-use

廉价感情. 提交于 2019-12-06 05:19:55

You may subclass Zend_Form and overload render method to generate id's automatically:

public function render()
{
    $elements = $this->getElements();
    foreach ($elements as $element) {
        $element->setAttrib('id', $this->getName() . '_' . $element->getId();
    }
}

This is just a pseudo-code. Of course, you may modify this to suit your needs.

You could add a static integer property (let's say self::$counter)to your Zend_Form inherited class. You increment it on the init() method. For each element you create on your Zend_Form object you append that property to your element :

$element->setAttrib('id', self::$counter + '_myId');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!