/**
  * Helper function for generating simple checkbox HTML fragments
  *
  * @param Zend_Form_Element_Checkbox $element
  * @param string $cssEtc optional attribute string for <input> tags
  * @param string $wrapInputHtml optional HTML that wraps each <input>, split by an asterisk
  * @param string $wrapLabelHtml optional HTML that wraps each <label>, split by an asterisk
  *
  * @return string
  */
 public function simpleCheckbox($element, $cssEtc = '', $wrapInputHtml = '', $wrapLabelHtml = '')
 {
     $wrapInputHtmlStart = $wrapInputHtmlEnd = $wrapLabelHtmlStart = $wrapLabelHtmlEnd = '';
     if (strpos($wrapInputHtml, '*') !== false) {
         list($wrapInputHtmlStart, $wrapInputHtmlEnd) = explode('*', $wrapInputHtml);
     }
     if (strpos($wrapLabelHtml, '*') !== false) {
         list($wrapLabelHtmlStart, $wrapLabelHtmlEnd) = explode('*', $wrapLabelHtml);
     }
     $output = '';
     $checkedValue = $element->options['checkedValue'];
     $output .= sprintf("%s<input type=\"checkbox\" name=\"%s\" id=\"%s\" value=\"%s\"%s%s />%s<label for=\"%s\">%s</label>%s%s\n", $wrapInputHtmlStart, $element->getName(), $element->getId(), $checkedValue, (string) $checkedValue == (string) $element->getValue() ? ' checked="checked"' : '', $cssEtc != '' ? " {$cssEtc}" : '', $wrapLabelHtmlStart, $element->getId(), $element->getLabel(), $wrapLabelHtmlEnd, $wrapInputHtmlEnd);
     return $output;
 }
Exemple #2
0
 public function testSetOptionsSetsInitialValueAccordingToSubmittedValues()
 {
     $options = array('test1' => array('value' => 'foo', 'checkedValue' => 'foo', 'uncheckedValue' => 'bar'), 'test2' => array('value' => 'bar', 'checkedValue' => 'foo', 'uncheckedValue' => 'bar'));
     foreach ($options as $current) {
         $element = new Zend_Form_Element_Checkbox('test', $current);
         $this->assertEquals($current['value'], $element->getValue());
         $this->assertEquals($current['checkedValue'], $element->getCheckedValue());
         $this->assertEquals($current['uncheckedValue'], $element->getUncheckedValue());
     }
 }