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

Disable form select entity by function


I have a select form entity like this:

use \Phalcon\Forms\Element\Select;

$select = new Select('select', array(
    'NULL' => '',
    'a' => 'Option 1',
    'b' => 'Option 2',

I would like to have Option 1 to be disabled if some variable is true. How can I do that? Wanted result:

  <option value=""></option>
  <option value="" disabled>Option 1</option>
  <option value="">Option 2</option>


I would do it the old facion way:

in my view:

foreach ($this->view->mySelectOptions AS $key => $value){

                $disabled = "";

                if ($value['myTruOption'] === true){
                    $disabled = "disabled=\"disabled\"";

                echo "<option $disabled>".$value['name]'."</option>";

in the controller

$this->view->setVar('mySelectOptions', MyWonderfulModel::find() /* ->toArray() ?*/ );