【问题标题】:display checked input field in cakephp 3在 cakephp 3 中显示选中的输入字段
【发布时间】:2019-01-03 12:03:30
【问题描述】:

当我在$selected 变量中获取值时,我必须显示复选框。目前在下面的场景中,我必须显示两个复选框已选中,但我的代码不起作用。我该如何解决?

$checkboxarray = [
    '0' => "By Value",
    '1' => "By Quantity",
    '2' => "By Date"
];
$selected = explode(",", "0,1");
echo $this->Form->select('mo_type', $checkboxarray, array( 'selected' => $selected, 'multiple' => 'checkbox'));

【问题讨论】:

  • 键不是'选择',而是'值'

标签: php cakephp cakephp-3.0 cakephp-3.3


【解决方案1】:

你可以试试default而不是selected属性,

$checkboxarray = [
    '0' => "By Value",
    '1' => "By Quantity",
    '2' => "By Date"
];
$selected = explode(",", "0,1");
echo $this->Form->select('mo_type', $checkboxarray, array( 'default' => $selected, 'multiple' => 'checkbox'));

正确的方法是使用“val”属性

echo $this->Form->select('mo_type', $checkboxarray, array( 'val' => $selected, 'multiple' => 'checkbox'));

【讨论】:

  • 实际上似乎为多选设置默认值的正确方法是'val',见here
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-29
  • 1970-01-01
  • 2017-12-06
  • 2023-03-06
相关资源
最近更新 更多