OldWest
OldWest

Reputation: 2385

CakePHP label option on input select form not working as expected

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?

Upvotes: 2

Views: 11661

Answers (1)

joebeeson
joebeeson

Reputation: 4366

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.

Upvotes: 8

Related Questions