コード例 #1
0
ファイル: PFormElement.php プロジェクト: GemsTracker/MUtil
 /**
  * Apply this element to the form as the output decorator.
  *
  * @param \Zend_Form $form
  * @param mixed $width The style.width content for the labels
  * @param array $order The display order of the elements
  * @param string $errorClass Class name to display all errors in
  * @return \MUtil_Html_DlElement
  */
 public function setAsFormLayout(\Zend_Form $form, $width = null, $order = array('label', 'element', 'description'), $errorClass = 'errors')
 {
     $this->_repeatTags = true;
     $prependErrors = $errorClass;
     // Make a Lazy repeater for the form elements and set it as the element repeater
     $formrep = new \MUtil_Lazy_RepeatableFormElements($form);
     $formrep->setSplitHidden(true);
     // These are treated separately
     $this->setRepeater($formrep);
     if (null === $width) {
         $attr = array();
     } else {
         $attr['style'] = array('display' => 'inline-block', 'width' => $width);
     }
     // Place the choosen renderers
     foreach ($order as $renderer) {
         switch ($renderer) {
             case 'label':
                 $this->label($formrep->element, $attr);
                 // Set label with optional width
                 break;
             case 'error':
                 $prependErrors = false;
                 // Intentional fall through
             // Intentional fall through
             default:
                 $this->append($formrep->{$renderer});
         }
     }
     // Set this element as the form decorator
     $decorator = new \MUtil_Html_ElementDecorator();
     $decorator->setHtmlElement($this);
     $decorator->setPrologue($formrep);
     // Renders hidden elements before this element
     if ($prependErrors) {
         $decorator->setPrependErrors(\MUtil_Html_ListElement::ul(array('class' => $errorClass, 'style' => array('margin-left' => $width))));
     }
     $form->setDecorators(array($decorator, 'AutoFocus', 'Form'));
     return $this;
 }
コード例 #2
0
ファイル: DlElement.php プロジェクト: GemsTracker/MUtil
 /**
  * Apply this element to the form as the output decorator.
  *
  * @param \Zend_Form $form
  * @param mixed $width The style.width content for the labels
  * @param array $order The display order of the elements
  * @return \MUtil_Html_DlElement
  */
 public function setAsFormLayout(\Zend_Form $form, $width = null, array $order = array('element', 'errors', 'description'))
 {
     // Make a Lazy repeater for the form elements and set it as the element repeater
     $formrep = new \MUtil_Lazy_RepeatableFormElements($form);
     $formrep->setSplitHidden(true);
     // These are treated separately
     $this->setRepeater($formrep);
     if (null === $width) {
         $attr = array();
     } else {
         $attr['style'] = array('width' => $width);
     }
     $this->dt()->label($formrep->element, $attr);
     // Set label dt with optional width
     $dd = $this->dd();
     foreach ($order as $renderer) {
         $dd[] = $formrep->{$renderer};
     }
     // $this->dd($formrep->element, ' ', $formrep->errors, ' ', $formrep->description);
     // $this->dd($formrep->element, $formrep->description, $formrep->errors);
     // Set this element as the form decorator
     $decorator = new \MUtil_Html_ElementDecorator();
     $decorator->setHtmlElement($this);
     $decorator->setPrologue($formrep);
     // Renders hidden elements before this element
     $form->setDecorators(array($decorator, 'AutoFocus', 'Form'));
     return $this;
 }