I know many of framework users are tired with default value option for forms.Here is method you can use for cakephp.
create('Post', array(
'url' => '/posts/index',
'type' => 'file',
));
echo $form->input('text', array(
'type' =>'text',
'value' => 'default value',
));
echo $form->input('textarea', array(
'type' =>'textarea',
'value' => 'default value',
));
$options = array(
'1' => 'Option 1',
'2' => 'Option 2',
'3' => 'Option 3',
);
echo $form->input('select', array(
'type' =>'select',
'options' => $options,
'selected' => 2,
'empty' => 'Please Select'
));
echo $form->input('multiple_select', array(
'type' =>'select',
'options' => $options,
'selected' => 2,
'empty' => 'Please Select Multiple',
'multiple' => true
));
echo $form->input('checkbox', array(
'type' =>'select',
'multiple'=> 'checkbox',
'options' => $options,
'selected' => 2,
));
echo $form->input('radio', array(
'type' =>'radio',
'options' => $options,
'legend' => 'Radio',
'default' => '2'
));
?>
CheckBoxes
input('checkbox2', array(
'type' => 'checkbox',
'value' =>'1',
'checked' => 'checked',
'label' => 'Choice 1'
));
echo $form->input('checkbox2', array(
'type' => 'checkbox',
'value' =>'2',
'label' => 'Choice 2'
));
?>
input('file', array(
'type' => 'file',
'label' => 'Browse File'
));
echo $form->input('date', array(
'type' => 'date',
'label' => 'Date',
'minYear' => 1900,
'maxYear' => 2010,
# default order m/d/y
'selected' => array(
'month' => '03',
'day' => '09',
'year' => '1977'
),
));
echo $form->input('time', array(
'type' => 'time',
'label' => 'Time',
'selected' => array(
'hour' => '12',
'min' => '15',
'meridian' => 'pm'
),
));
echo $form->input('datetime', array(
'type' => 'datetime',
'label' => 'Date Time',
'minYear' => 1900,
'maxYear' => 2010,
# default order m/d/y
'selected' => array(
'month' => '03',
'day' => '09',
'year' => '1977',
'hour' => '13',
'min' => '10',
'meridian' => 'am'
),
));
echo $form->submit('Submit');
echo $form->end();
?>
Reference and thanks:azrilnazli.blogspot
0 comments:
Post a Comment