Question

when i need to use select form i see the first value is empty..but i dont need this empty value option ..how to do this..thanks

 <?php
    $options = array('M' => 'Male', 'F' => 'Female');
    echo $this->Form->select('gender', $options)
    ?>

Will output:

<select name="data[User][gender]" id="UserGender">
<option value=""></option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
Was it helpful?

Solution

In Cake 2.x, you can just add the 'empty'=>false like this (tested and works):

<?php
$options = array('M' => 'Male', 'F' => 'Female');
echo $this->Form->select('gender', $options, array('empty'=>false));
?>

In CakePHP 1.3.x (per this page in the book) you might have to add an additional null like this:

<?php
$options = array('M' => 'Male', 'F' => 'Female');
echo $this->Form->select('gender', $options, null, array('empty'=>false));
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top