CakePHP label option on input select form not working as expected
The API doesn't show three parameters to the FormHelper::input
method; there is only $fieldName
and $options
. You probably meant to use the FormHelper::select
method instead.
$this->Form->select('plan_detail_id', $plans_list, null, array('label' => 'Select a the Plan Detail', 'empty' => '-- Select a the Plan Detail --'));
Note that the FormHelper::select
does not include a wrapping <div>
or label. To do so you must pass in something like this..
echo $this->Form->input(
'plan_detail_id',
array(
'options' => $plans_list,
'type' => 'select',
'empty' => '-- Select a the Plan Detail --',
'label' => 'Select a the Plan Detail'
)
);
This differs from your original attempt in that it moves the $plans_list
into the array with the options
argument set.
OldWest
Updated on June 05, 2022Comments
-
OldWest almost 2 years
My select form is working perfectly, but my label will not display no matter the variation or arrangement of arguments.
Here is my code:
<?php echo $this->Form->input('plan_detail_id', $plans_list, array( 'type' => 'select', 'label' => 'Select a the Plan Detail', 'empty' => '-- Select a the Plan Detail --' )); ?>
As you can see I have a second argument
$plan_list
which is normally the place for the label tag. For example, all of my other labels like such are OK:<td><?php echo $this->Form->input('age_id', array( 'label' => 'Select an Age Range', 'empty' => '-- Select an Age Range --' )); ?></td>
Note: there is no second
$argument
like the first example. Am I doing something totally wrong? Or is this not possible or a bug? -
OldWest about 13 yearsTried that earlier and it does not work, and the pre-entered select item does not show either : (
-
joebeeson about 13 yearsDo you mean you get no code to show up? Define "does not work"
-
OldWest about 13 yearsThe predefined first select box goes away (from 'empty') and again no label displays above the select box. BUT in my code, the label DOES show in View Source??? Just won't show on the actual UI??
-
joebeeson about 13 yearsI fixed the answer. I forgot to include the
$selected
parameter in the query. -
OldWest about 13 yearsThat was my next thought. Thanks. Worked like a charm : )