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

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 :)