Search code examples
zend-frameworkzend-formzend-decoratorshtml

Zend_Form - prefix text using decorator


I want to prefix the form title within the form tags, but above the form elements.

<form>
 <h3>Login Form</h3>
 <!-- form elements -->
</form>

I do not want to use a view script.

I thought of using the Description decorator, but that appears to be only available to the elements.

How do I set an arbitrary description for a form, and position it (either append / prepend) within the form tags? I have a feeling I need to play with the HtmlTag decorator but I've played with it and can't get the right results.


Solution

  • Typical. Ask a question, work out the solution.

    $form->setDecorators(array(
        array(
            'Description',
            array(
                'tag' => 'div',
                'class' =>'title'
            )
        ),
        'FormElements',
        'Form'
    ))
    ->setDescription('Enter Login Credentials:');
    

    Depending where you place the description decorator will determine where in the form tags it displays, i.e. place above 'FormElements' to display above the elements; place below 'FormElements' to display the description below the elements; place below the 'Form' decorator to display after the form tags.