We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Cannot add attribute on options of select box

hi guys,

Im having hard tim in figuring on how to add the attribute "id" on each option in my select box? here is my code.


self::$registration_form['select'] = new Select('select',   
        [   //select value
            'male' => ['id' => 'opt1'],
            'female' => ['id' => 'opt1']
        [   //select class,id
            'class' => 'form-control gender',
            'id'    => 'gender'

it gives me the output

<select id="gender" name="select" class="form-control gender">
    <optgroup label="male">
    <option value="id">opt1</option>
    <optgroup label="female">
    <option value="id">opt1</option>
edited Nov '14

I just checked code of 2.0.0 branch and if logic is the same in 1.3.x then in my opinion the behaviour you want to use is not working out of the box.

I think you have to use a few loops to build the select manually.