3 final class AphrontFormCheckboxControl
extends AphrontFormControl
{
5 private $boxes = array();
8 public function setCheckboxKey($checkbox_key) {
9 $this->checkboxKey
= $checkbox_key;
13 public function getCheckboxKey() {
14 return $this->checkboxKey
;
17 public function addCheckbox(
23 $this->boxes
[] = array(
27 'checked' => $checked,
33 protected function getCustomControlClass() {
34 return 'aphront-form-control-checkbox';
37 public function setOptions(array $options) {
39 foreach ($options as $key => $value) {
46 $this->boxes
= $boxes;
51 protected function renderInput() {
53 foreach ($this->boxes
as $box) {
54 $id = idx($box, 'id');
56 $id = celerity_generate_unique_node_id();
59 $name = idx($box, 'name');
61 $name = $this->getName().'[]';
64 $value = $box['value'];
66 if (array_key_exists('checked', $box)) {
67 $checked = $box['checked'];
69 $checked = in_array($value, $this->getValue());
72 $checkbox = phutil_tag(
78 'value' => $box['value'],
79 'checked' => $checked ?
'checked' : null,
80 'disabled' => $this->getDisabled() ?
'disabled' : null,
88 $rows[] = phutil_tag('tr', array(), array(
89 phutil_tag('td', array(), $checkbox),
90 phutil_tag('th', array(), $label),
94 // When a user submits a form with a checkbox unchecked, the browser
95 // doesn't submit anything to the server. This hidden key lets the server
96 // know that the checkboxes were present on the client, the user just did
97 // not select any of them.
99 $checkbox_key = $this->getCheckboxKey();
101 $rows[] = phutil_tag(
105 'name' => $checkbox_key,
112 array('class' => 'aphront-form-control-checkbox-layout'),