Reputation: 1166
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>
Upvotes: 0
Views: 1807
Reputation: 29141
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));
?>
Upvotes: 1