Naveed Ramzan
Naveed Ramzan

Reputation: 3593

Create a SelectBox using Form Helper in CakePHP3

I am trying to make a combo box for an edit page.

echo $this->Form->select('status', 
                        ['empty' => 'Select Status'], 
                        ['class' => 'form-control', 'required']
                    );

Here I want to add 2 things :

$options = array('0' => 'Inactive',
                 '1' => 'Active',
                );

and selected value. suppose that is $status;

I tried with different options but sometime it do not add classes and sometime it shows options in tag

It will be great if somebody give clue.

Thanks

Upvotes: 1

Views: 229

Answers (1)

Jacek B Budzynski
Jacek B Budzynski

Reputation: 1413

<?= $this->Form->input('status', [
        'type' => 'select', 
        'options' => ['0' => __('Inactive') , '1' => __('Active')], 
        'empty' => __('Select Status'),
        'class' => 'form-control',
        'required' => true, 'label' => __('Type')
    ]) 
?>

Upvotes: 1

Related Questions