2012-08-01 3 views
0

나는 체크 박스 라벨을 만들고 입력하는 뷰 도우미를 만들었습니다. 내가 겪고있는 문제는 무시됩니다.젠드 폼 뷰 도우미

내 폼 요소는 다음과 같습니다

class Core_View_Helper_FormOther extends Zend_View_Helper_FormElement 
{ 

    public function formOther($name, $value = null, $attribs = null) 
    { 
     $labelStyle = ''; 
     $label = ''; 
     $checkboxAttrib = array('checked' => 1,'unchecked' => 0); 
     $textAttrib = array('size' => 10); 

     foreach ($attribs as $k => $v) 
     { 
      $a = str_replace(array('text-', 'checkbox-'), '', $k); 
      if (strpos($k, 'text-') !== false) 
      { 
       $textAttrib[$a] = $v; 
      } 
      if (strpos($k, 'checkbox-') !== false) 
      { 
       $checkboxAttrib[$a] = $v; 
      } 
     } 

     $textValue = ''; 
     $checkboxValue = $checkboxAttrib['unchecked']; 
     if (!empty($value)) 
     { 
      $checkboxValue = $checkboxAttrib['checked']; 
      $textValue = $value; 
     } 

     if (isset($attribs['checkboxLabel'])) 
     { 
      $label = $attribs['checkboxLabel']; 
     } 
     if (isset($attribs['checkboxLabelStyle'])) 
     { 
      $labelStyle = $attribs['checkboxLabelStyle']; 
     } 

     return $this->view->formCheckbox($name.'_check', $checkboxValue, null, $checkboxAttrib) 
      . ' <label style="'. $labelStyle .'">'. $label .'</label> ' 
      . $this->view->formText($name, $textValue, $textAttrib); 
    } 
} 

과 마지막이 함께 불렀다 :

require_once 'Zend/Form/Element/Xhtml.php'; 

class Core_Form_Element_Other extends Zend_Form_Element_Xhtml 
{ 

    public $helper = 'formOther'; 

    public function isValid ($value, $context = null) 
    { 
     return parent::isValid($value, $context); 
    } 

    public function getValue() 
    { 
     return parent::getValue(); 
    } 
} 

뷰 도우미가

$other = $this->createElement('Other', 'otherElem') 
      ->setAttrib('checkboxLabel', 'Other') 
      ->setAttrib('checkbox-checked', 'yes') 
      ->setAttrib('checkbox-unChecked', 'no') 
      ->setAttrib('checkboxLabelStyle', 'font-weight:normal;padding-right:0px;') 
      ->setAttrib('text-size', 20) 
      ->setDecorators(array(
       'ViewHelper', 
       array('Errors', array('class' => 'error small', 'placement' => Zend_Form_Decorator_Abstract::PREPEND)), 
       array('htmlTag', array('tag' => 'div', 'class' => 'span-8 last')) 
      )); 
     $this->_telements[] = $other; 
정확히 당신이 '가 무슨 뜻 이죠

답변

0

'채우다'? 확인란을 선택하지 않은 상태에서 양식을 제출할 때 값이 누락되면 기본 HTML 동작입니다.

언제든지 체크 박스 자체를 'checked = "checked"속성으로 설정합니까? 체크 박스와 체크의 가치는 다른 것들입니다.

내 생각에 사용자 정의 데코레이터를 사용하는 것은 젠드 양식을 스타일링하는 가장 잘못된 방법입니다. zend에서 기본 html을 출력하고 jQuery로 폼 레이블을 멋지게 만드십시오. 젠드 양식은 많은 것들에 유용하지만 스타일과 배열은 그 중 하나가 아닙니다.