Add some html to Zend Forms

后端 未结 10 1190
天命终不由人
天命终不由人 2020-11-30 04:17

Im looking for a simple bit of code that will let me add the following html into my zend form:

10条回答
  •  余生分开走
    2020-11-30 05:00

    • Create a custom Decorator that return the label(or anything else):

      class My_Decorator_CustomHtml extends Zend_Form_Decorator_Abstract {
                  public function render($content)
              {
                  $element = $this->getElement();
                  if (!$element instanceof Zend_Form_Element) {
                      return $content;
                  }
                  if (null === $element->getView()) {
                      return $content;
                  }
                  $html = $element->getLabel();
                  return $html;
             }
      
      
      }
      
    • Place this in the decorator path

      $form->addElementPrefixPath('My_Decorator',
                                  'My/Decorator/',
                                  'decorator');

    • Create the element and put the custom html in the label

      $html = '

      some text....
      '; $element = new Zend_Form_Element_Hidden('hidden-input', array( 'label'=>$html, ));
      $element->setDecorators(array('CustomHtml')); //add it to the form $form->addElement($element);

    and that's it

提交回复
热议问题