私はゼンドに取り組んでいます。いくつかのチェックボックスを含むフォームがあります。データベースからデータを取得し、このデータをこのフォームに入力したいと考えています。「1」がテーブル フィールドに保存されている場合は、チェック ボックスをオンにします。それ以外の場合は、そのままにしておきます。テキストボックスとドロップダウンでは、データは簡単に取り込まれますが、実際にチェックボックスをチェックする方法。
form.php で次のようなチェックボックスとテキストボックス要素を作成しています。
// Person name
$person = $this->CreateElement('text', 'name');
$person->setLabel('Name');
$elements[] = $person;
// Organization name
$person = $this->CreateElement('text', 'organization');
$person->setLabel('Organization');
$elements[] = $person;
// isAdmin Checkbox
$isAdmin = $this->CreateElement('checkbox', 'isAdmin');
$isAdmin->setLabel('Admin');
$elements[] = $isAdmin;
$this->addElements($elements);
$this->setElementDecorators(array('ViewHelper'));
// set form decorator (what script will render the form)
$this->setDecorators(array(array('ViewScript' , array('viewScript' => 'organization/accessroles-form.phtml'))));
フォームのレンダリング方法:
<form name="myform" action="<?= $this->element->getAction() ?>" method="<?= $this->element->getMethod() ?>" id="accessrolesform">
<table align="center" width="100%" border="0"><tbody>
<tr>
<td><?= $this->element->name ?></td>
</tr>
<tr>
<td><?= $this->element->organization ?></td>
</tr>
<tr>
<td><?= $this->element->isAdmin ?></td>
</tr>
</table>
</form>
そして、次のようなデータを取り込みます (例):
// Prepare data to populate
$data['name'] = 'Naveed';
$data['organization'] = 'ABC';
$data['isAdmin'] = '1';
// Populate editable data
$this->view->form->populate( $data );
テキストボックスにデータを入力していますが、チェックボックスをチェックしていませんか? アクションからチェックボックスをチェックする方法はありますか?
ありがとう