1
我正在創建一個表單並添加一個複選框與ZF2,但由於某些原因,選項不會發送時,我使用數組表示法。zf2 ZendForm中的複選框創建失敗,數組表示法
所以這個:
class PageForm extends Form
{
public function __construct($name = null)
{
$checkbox = new Element\Checkbox('system');
$checkbox ->setLabel('System Page')
->setUseHiddenElement(true)
->setCheckedValue("1")
->setUncheckedValue("0");
$this->add($checkbox);
}
}
正常工作, 但這:
class PageForm extends Form
{
public function __construct($name = null)
{
$this->add(array(
'type' => 'Checkbox',
'name' => 'checkbox',
'options' => array(
'label' => 'A checkbox',
'use_hidden_element' => true,
'checked_value' => 'good',
'unchecked_value' => 'bad'
)
}
}
創建複選框,但沒有選中/取消的價值觀,我想知道如果我做錯了什麼,還是錯過了一個步驟? (例子是直接從文檔)
這是在視圖代碼:
$form = $this->form;
$form->setAttribute('action', $this->url('page', array('action' => 'add')));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formCollection($form);
echo $this->form()->closeTag();
感謝
這個工作太謝謝了,你知道如果有任何理由的常規復選框不適用數組符號? – Juan 2013-03-04 17:25:16
也許是因爲你在使用集合視圖助手來渲染?嘗試使用formCheckbox幫手.. – Andrew 2013-03-05 08:50:01