How could I add attributes to <option> tags using Zend Framework?
// Doing this:
$e = new Zend_Form_Element_Select('combo');
$e->addMultiOptions(array(1=>'Jan',2=>'Feb'));
$e->renderViewHelper();
// I'll get something like this;
<select name="combo" id="combo">
<option value="1">Jan</option>
<option value="2">Feb</option>
</select>
How could I add attributes to tags usi开发者_如何学JAVAng Zend Framework?
// I mean, I wanna get something like this:
<select name="combo" id="combo">
<option abc="123" value="1">Jan</option>
<option abc="456" value="2">Feb</option>
</select>
I think you will have to create your own class extending Zend_Form_Element
The helper that builds the HTML for the Zend_Form_Element_Select is Zend_View_Helper_FormSelect. This helper builds the elements in the _build function. This function only creates tags with the following attributes:
- value
- label
- selected
- disabled
If you would like more options you would need to create your own form element with your own helper for rendering. I would suggest overriding the existing ones and just changing this specific part.
Kind regards,
Robin
精彩评论