CakePHP普通输入框预填充但不填充选择框?

jfewjypa  于 2022-11-11  发布在  PHP
关注(0)|答案(1)|浏览(137)

我正在使用Cake的表单助手,当我在我的控制器中设置$this->request->data时,它应该是预填充的。它是预填充普通的type="text"输入框,但不是预填充type=“select”。有人知道为什么吗?
如果我pr($this->request->data)在我看来我得到这个结果:

Array
(
  [EventInvoiceHardsurface] => Array
    (
        [id] => 7868
        [expediting_notes] => Fake expiditing notes
        [installation_notes] => Fake installation notes.  
    )

  [PurchasingProduct] => Array
    (
        [style_number] => BDP
        [style_name] => DUNDEE PLANK 3 1/4
    )

  [PurchasingProductColor] => Array
    (
        [name] => CB1230 SEASHELL
    )

)

这不会预先填充

<?=$this->Form->input('PurchasingProductColor.name', array('type' => 'select', 'label' => 'Product Color', 'div' => false, 'placeholder' => 'Color Name', 'class' => 'input-medium', 'disabled' => 'disabled', 'empty' => true));?>

但这确实

<?=$this->Form->input('PurchasingProductColor.name', array('type' => 'text', 'label' => 'Product Color', 'div' => false, 'placeholder' => 'Color Name', 'class' => 'input-medium', 'disabled' => 'disabled', 'empty' => true));?>

我试过删除'empty' =〉true,删除占位符,删除disabled,但这些都没有什么不同。
有什么想法吗?谢谢。
编辑:
我只是用了这个。

<?=$this->Form->input('PurchasingProductColor.name', array('type' => 'select', 'label' => 'Product Color', 'div' => false, 'placeholder' => 'Color Name', 'class' => 'input-medium', 'options' => array((!empty($this->request->data['PurchasingProductColor']['id']) ? $this->request->data['PurchasingProductColor']['id'] : '') => (!empty($this->request->data['PurchasingProductColor']['name']) ? $this->request->data['PurchasingProductColor']['name'] : ''))));?>

我失去了empty =〉true功能和禁用的功能,但我将通过JavaScript控制这些功能。

  • 谢谢-谢谢
w51jfk4q

w51jfk4q1#

您必须提供选项

<?=$this->Form->input('PurchasingProductColor.name', 
array('type' => 'select', 'label' => 'Product Color', 'div' => false, 
'placeholder' => 'Color Name', 'class' => 'input-medium', 
'disabled' => 'disabled', 'empty' => true,'options'=>$optionsList));?>

$optionsList是一个选择框的选项列表,它将预先选择您的特定选择。

相关问题