Add some html to Zend Forms

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

    The only way I can think of at the moment is to add a dummy element to the form and remove all decorators except an 'HtmlTag' with the attributes you specified in your question. Removing the decorators means that the actual element will not be rendered - only the HtmlTag decorator will be rendered.

    so assuming your form is $form:

    $form->addElement(
        'hidden',
        'dummy',
        array(
            'required' => false,
            'ignore' => true,
            'autoInsertNotEmptyValidator' => false,
            'decorators' => array(
                array(
                    'HtmlTag', array(
                        'tag'  => 'div',
                        'id'   => 'wmd-button-bar',
                        'class' => 'wmd-panel'
                    )
                )
            )
        )
    );
    $form->dummy->clearValidators();
    

    Note that you want to prevent any validation of the element. This is only one way - there are likely others.

    Output:

    There is a good article describing decorators.

提交回复
热议问题