We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 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.

<?php

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>
    <optgroup label="female">
    <option value="id">opt1</option>
    </optgroup>
</select>
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.