输入选择表单上的 CakePHP 标签选项未按预期工作

标签 cakephp forms label helper

我的选择表单工作正常,但无论参数如何变化或排列,我的标签都不会显示。

这是我的代码:

<?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 --'
)); ?>

正如你所看到的,我有第二个参数$plan_list,它通常是标签标记的位置。例如,我的所有其他类似标签都可以:

<td><?php echo $this->Form->input('age_id', array(
    'label' => 'Select an Age Range',
    'empty' => '-- Select an Age Range --'
)); ?></td>

注意:没有像第一个示例那样的第二个$argument。我做错了什么吗?或者这是不可能的或者是一个错误?

最佳答案

The API doesn't show three parametersFormHelper::input方法;只有$fieldName$options 。您可能想使用FormHelper::select方法代替。

$this->Form->select('plan_detail_id', $plans_list, null, array('label' => 'Select a the Plan Detail', 'empty' => '-- Select a the Plan Detail --'));

请注意 FormHelper::select不包括包装<div>或标签。为此,您必须传递类似这样的内容..

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'
    )
);

这与您最初的尝试不同,因为它移动了 $plans_list进入数组 options参数集。

关于输入选择表单上的 CakePHP 标签选项未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4949669/

相关文章:

php - Cakephp生成xml错误-空白

mysql - 我可以在 CakePHP 中重新创建以下 MySQL 查询吗?

php - 如何从 php 向 iphone 发送正确的 html 数据?

jquery - float 条形图数据标签左偏移

json - 在 CakePHP 中强制 JSON 响应

html - 将具有特定 ID 的 HTML 表单封装在新标签中

forms - 使用变量定义表单输入中的默认值

javascript - 动态添加 HTML 元素后创建一个 jQuery 事件

php - Laravel Blade 中 Label 标签中的单选按钮

html - 如何防止通过单击单选按钮的标签来选择单选按钮