public function testSetIdFromAttribs() { $helper = new Zend_View_Helper_FormCheckbox(); $element = $helper->formCheckbox('foo', null, array('id' => 'bar')); $this->assertContains('name="foo"', $element); $this->assertContains('id="bar"', $element); }
/** * dijit.form.CheckBox * * @param int $id * @param string $content * @param array $params Parameters to use for dijit creation * @param array $attribs HTML attributes * @param array $checkedOptions Should contain either two items, or the keys checkedValue and uncheckedValue * @return string */ public function checkBox($id, $value = null, array $params = array(), array $attribs = array(), array $checkedOptions = null) { // Prepare the checkbox options require_once 'Zend/View/Helper/FormCheckbox.php'; $checked = false; if (isset($attribs['checked']) && $attribs['checked']) { $checked = true; } elseif (isset($attribs['checked'])) { $checked = false; } $checkboxInfo = Zend_View_Helper_FormCheckbox::determineCheckboxInfo($value, $checked, $checkedOptions); $attribs['checked'] = $checkboxInfo['checked']; if (!array_key_exists('id', $attribs)) { $attribs['id'] = $id; } $attribs = $this->_prepareDijit($attribs, $params, 'element'); // strip options so they don't show up in markup if (array_key_exists('options', $attribs)) { unset($attribs['options']); } // and now we create it: $html = ''; if (!strstr($id, '[]')) { // hidden element for unchecked value $html .= $this->_renderHiddenElement($id, $checkboxInfo['uncheckedValue']); } // and final element $html .= $this->_createFormElement($id, $checkboxInfo['checkedValue'], $params, $attribs); return $html; }
/** * Generates a 'text' element. * * @access public * * @param string|array $name If a string, the element name. If an * array, all other parameters are ignored, and the array elements * are used in place of added parameters. * * @param mixed $value The element value. * * @param array $attribs Attributes for the element tag. * * @return string The element XHTML. */ public function formTextOverwrite($name, $value = null, $attribs = null) { $info = $this->_getInfo($name, $value, $attribs); extract($info); // name, value, attribs, options, listsep, disabled $viewHelperFormCheckbox = new Zend_View_Helper_FormCheckbox(); $viewHelperFormCheckbox->setView($this->view); $viewHelperFormElement = new Zend_View_Helper_FormText(); $viewHelperFormElement->setView($this->view); $checked = ''; if ($attribs['overwrite']) { $checked = 'checked'; $disabled = true; unset($attribs['overwrite']); } else { $disabled = false; if (isset($attribs['class']) && $attribs['class'] != '') { $attribs['class'] = $attribs['class'] . ' disabled'; } else { $attribs['class'] = 'disabled'; } } $separator = ''; if (isset($attribs['separator'])) { $separator = $attribs['separator']; unset($attribs['separator']); } $xhtml = '<div class="input-prepend">'; $xhtml .= '<label class="add-on">'; $xhtml .= $viewHelperFormCheckbox->formCheckbox($name . '[overwrite]', null, array_merge($attribs, array('checked' => $checked, 'class' => 'checkbox text-overwrite-checkbox'))); $xhtml .= '</label>'; $xhtml .= ' ' . $separator; if (!$disabled) { $xhtml .= $viewHelperFormElement->formText($name . '[value]', $value, array_merge($attribs, array('disabled' => 'disabled'))); } else { $xhtml .= $viewHelperFormElement->formText($name . '[value]', $value, $attribs); } $xhtml .= '</div>'; return $xhtml; }
public function formCheckbox($name, $value = null, $attribs = null, array $checkedOptions = null) { $inputLabel = isset($attribs['input_label']) ? $attribs['input_label'] : null; if (is_array($attribs)) { unset($attribs['input_label']); } $xhtml = parent::formCheckbox($name, $value, $attribs, $checkedOptions); if (!isset($attribs['escape']) || $attribs['escape']) { $inputLabel = $this->view->escape($inputLabel); } // Wraps the checkbox with its own label (not the decorator one), // if the attrib input_label is added if ($inputLabel) { $xhtml = '<label class="checkbox"' . ' for="' . $this->view->escape($name) . '">' . $xhtml . $inputLabel . '</label>'; } return $xhtml; }
/** * dijit.form.CheckBox * * @param int $id * @param string $content * @param array $params Parameters to use for dijit creation * @param array $attribs HTML attributes * @return string */ public function checkBox($id, $value = null, array $params = array(), array $attribs = array(), array $checkedOptions = null) { // Prepare the checkbox options require_once 'Zend/View/Helper/FormCheckbox.php'; $checked = false; if (isset($attribs['checked']) && $attribs['checked']) { $checked = true; } elseif (isset($attribs['checked'])) { $checked = false; } $checkboxInfo = Zend_View_Helper_FormCheckbox::determineCheckboxInfo($value, $checked, $checkedOptions); $attribs['checked'] = $checkboxInfo['checked']; $attribs = $this->_prepareDijit($attribs, $params, 'element'); // and now we create it: $html = ''; if (!strstr($id, '[]')) { // hidden element for unchecked value $html .= '<input name="' . $id . '" type="hidden" value="' . $this->view->escape($checkboxInfo['unCheckedValue']) . '"' . $this->getClosingBracket(); } // and final element $html .= $this->_createFormElement($id, $value, $params, $attribs); return $html; }
public function formCheckbox($name, $value = null, $attribs = null, array $checkedOptions = array(1, 0)) { return parent::formCheckbox($name, $value, $attribs, $checkedOptions); }