texai
texai

Reputation: 3736

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 using 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>

Upvotes: 0

Views: 980

Answers (2)

AquaRobin
AquaRobin

Reputation: 16

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

Upvotes: 0

piddl0r
piddl0r

Reputation: 2449

I think you will have to create your own class extending Zend_Form_Element

Upvotes: 1

Related Questions