We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Optgroup in Forms/Element/Select

Hey, how should I add optgroup to Select tag for Forms? I'd like to create something like this:

<optgroup label="Alaskan/Hawaiian Time Zone">
    <option value="AK">Alaska</option>
    <option value="HI">Hawaii</option>
</optgroup>

Many thanks for the prompt reply!



765
Accepted
answer
edited Sep '14

Hello Sir,

you can add optgroups in your form via:

<?php
// ...
$this->add(new Select("status", array(
     "Active" => array('A1' => 'A One', 'A2' => 'A Two'), // "Active" = OptGroupTitle
     "B" => "B One"
)));

source: https://github.com/phalcon/cphalcon/pull/1463



3.0k

Thanks, works perfectly :)