Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

<div id="wmd-button-bar" class="wmd-panel"></div>

Thats it, it needs to be above my 'method' element in the form but thats it. For such a simple action I cant find any methods that don't involve me learning rocket science (i.e Zend Decorators).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

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:

<div id="wmd-button-bar" class="wmd-panel"></div>

There is a good article describing decorators.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...