0
votes

I'm pretty sure I don't have this problem in Cake 1.3, but:

I have a form input based on an is_live db field (containing 1 or 0 as its value).

The following creates a correctly populated checkbox:

echo $this->Form->input('is_live', array('label'=>'Status'));

However, the following does not seem to create a correctly populated dropdown (the first option is always selected, even though selecting an item and submitted the form does update correctly):

echo $this->Form->input('is_live', array(
    'label'=>'Status', 'type'=>'select' , 'options'=>array(1=>'Live', 0=>'Pending')
));

Is there anything simple I can do to make the dropdown populate based on the value of is_live in CakePHP 2.0? Or is there a workaround?

2
if my answer is not good enough, or that you have found a better solution please indicate. thank you.Kim Stacks

2 Answers

0
votes

I had the same issue with using 1 and 0 before.

My solution is to use the following

$options = array(1=> 'Live', 0=>'Pending');

echo $this->Form->input('YourModel.is_live',
    array(
        'options' => $options, 
        'label' => 'Status', 
        'selected' => intval($defaultValue), // make sure you set a default value
    )
); 
-1
votes

Can you change the content length of that field? If you can, change it to 2. This will get around the problem.

ALTER TABLE `your_table` CHANGE `is_live` `is_live` TINYINT(2)  NULL  DEFAULT NULL;