Monday, March 12, 2012

Form Helper

When using the Form helper to create a form, there are some options you can utilize to make your forms better.

Radio

The following form radio selection is named 'Radio name' and lists two options, 'label1' and 'label2', with 'label1' selected by default.
echo $this->Form->input('Radio name', array('type' => 'radio', 'legend' => false, 'options' => array('value1' => 'label1', 'value2' => 'label2'), 'default' => 'value1')); 

Selection

The following form selection displays a select box with 4 directions and their corresponding single letter values and includes an empty first selection and a default selection of West.
$dirs = array('N' => 'North', 'E' => 'East', 'S' => 'South', 'W' => 'West');
echo $this->Form->input('street_dir', array('label' => __('Direction', true), 'type' => 'select', 'options' => $dirs, 'empty' => true, 'default' => 'W'));