Add some html to Zend Forms

后端 未结 10 1143
天命终不由人
天命终不由人 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 04:46

    You have to add decorator.

    Any markup decorator may be helpful.

    For further information about decorators see: http://www.slideshare.net/weierophinney/leveraging-zendform-decorators

    0 讨论(0)
  • How about using some JQuery:

    Something like:

    <script language="javascript">
        $(document).ready(function() {
            $('#submit-element').append('<div id="wmd-button-bar" class="wmd-panel"></div>');
        });
    </script>
    
    0 讨论(0)
  • 2020-11-30 04:54

    You can create your own view helper libraray--App>View>Helper>PlainTextElemet.php

    Create a folder in your library folder that name is App so a folder that name is View so in View create Helper Folder so in Helper folder create a class with PlainTextElement name same following

     class App_View_Helper_PlainTextElement extends Zend_View_Helper_FormElement {
    
            public function PlainTextElement($name, $value = null, $attribs = null) {
                $info = $this->_getInfo($name, $value, $attribs);
                extract($info); // name, value, attribs, options, listsep, disable
                if (null === $value) {$value = $name;}
    
                return $value;
              }
    
        }
    

    Then in libray same above create a class App>Form>Element>PlainText.php

    And put folowing code in this class

    class App_Form_Element_PlainText extends Zend_Form_Element_Xhtml {
    
        public $helper='PlainTextElement';
    
        public function isValid($value){
    
            return true;
        }
    }
    

    Now in your form you can create each html code you like:

    $someValue = '<div id="wmd-button-bar" class="wmd-panel"></div>';
    
            $this->addElement(new App_Form_Element_PlainText('pliantext1', array(
                                'value'=>$someValue,
            )));
    

    Don't forget in your application.ini add fllowing lines too:

     autoloaderNamespaces.app = "App_"
     resources.view.helperPath.App_View_Helper="App/View/Helper"
    
    0 讨论(0)
  • 2020-11-30 04:56

    You can try this way, no config, just one extension class reference: http://www.zfsnippets.com/snippets/view/id/50

    <?php
    
    /**
     * Form note element
     *
     * @author Ruslan Zavackiy <ruslan.zavackiy@gmail.com>
     * @package elements
     */
    
    /**
     * Loads helper Zend_View_Helper_FormNote
     */
    
    class Custom_Form_Element_Note extends Zend_Form_Element_Xhtml
    {
        public $helper = 'formNote';
    }
    ?>
    

    then

    $companies->addElement('note', 'companyNote', array(
                'value' => '<a href="javascript:;" id="addCompany">Add Company</a>'
            ));
    
    0 讨论(0)
  • 2020-11-30 04:58

    This functionality is built into Zend via Zend_Form_Element_Note.

    new Zend_Form_Element_Note('forgot_password', array(
        'value' => '<a href="' . $this->getView()->serverUrl($this->getView()->url(array('action' => 'forgot-password'))) . '">Forgot Password?</a>',
    ))
    
    0 讨论(0)
  • 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

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

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

      $html = '<div id="wmd-button-bar" class="wmd-panel">some text....</div>'; $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

    0 讨论(0)
提交回复
热议问题