Tuesday, January 18, 2022

[FIXED] How do I set the default drop-down list?

Issue

I encountered such a problem, CakePHP created a drop-down list, but I can not figure out how to set it to the default value, if the user did not choose that the system set the default value by itself. And how can you give it a placeholder, such as that there is no one inside to say "Choose"?

Tell me, please, in advance grateful.

At the moment the list has this kind of appearance

enter image description here

Code Listing of the drop-down list

$this->Form->select('progress', array([0 => 'One', 1=> 'Two', 2=>'Three']));

Solution

Try this:

$this->Form->select('progress', [0 => 'One', 1=> 'Two', 2=>'Three'], ['empty' => '(Choose One)']);


Answered By - Derek

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.