Search code examples
formscakephphtml-selectdisabled-inputcakephp-3.1

CakePHP3.1: disable options in a select input


I want to disable options in a select input so I tried:

echo $this->Form->select("status", 
    [
    'options' => $status, 
    'value' => $order->status, 
    'label' => false, 
    'disabled' => [1, 2]
    ]);

But it doesn't generate any disabled statement in html code.

What's my mistake?


Solution

  • the correct way to set the attributes to the select's options is to pass an array like this

    $options = [
        [ 'text' => 'option 1', 'value' => 'value 1', 'disabled' => true],
        [ 'text' => 'option 2', 'value' => 'value 2', 'disabled' => true],
        [ 'text' => 'option 3', 'value' => 'value 3'],
        [ 'text' => 'option 4', 'value' => 'value 4']
    ];
    
    echo $this->Form->select(
        'status', 
        $options, 
        ['value' => $order->status, 'label' => false]
    );