Welcome to the Cookbook

loading...

7.3.5.17 select

select(string $fieldName, array $options, mixed $selected, array $attributes, boolean $showEmpty)

Creates a select element, populated with the items in $options, with the option specified by $selected shown as selected by default. Set $showEmpty to false if you do not want an empty select option to be displayed.

<?php
$options=array('M'=>'Male','F'=>'Female');
echo $form->select('gender',$options)
?>
  1. <?php
  2. $options=array('M'=>'Male','F'=>'Female');
  3. echo $form->select('gender',$options)
  4. ?>

Will output:

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