Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP custom values on select input

Tags:

html

php

cakephp

I am trying to create a select input field. However I want to set the values of each individual option manually.

in an attempt I tried the following:

echo $this->Form->input('field', array(
    'options' => array('Active', 'Blocked', 'Pending', 'Unknown'),
    'values' => array(1,2,0,99),
    'empty' => '(choose one)'
));

However this did not help (i.e 'Active' was 0, 'Blocked' was 1 etc...)

Does anyone know if it is possible to manually set the values?

like image 436
Marc Avatar asked Jul 14 '26 21:07

Marc


1 Answers

values is not the right key, you need to leverage the options array for it, as well:

'options' => array(1 => 'Active', 2 => 'Blocked', 0 => 'Pending', 99 => 'Unknown'),

but that is basic PHP (since non-defined keys are numerically indexed starting off at 0).

like image 66
mark Avatar answered Jul 16 '26 11:07

mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!