0

I'm writing my first Zend PHP app and I need some help. I'm generating my form through creating class extending Zend_Form and in init() I'm adding elements like:

    $user = $this->addElement('text', 'user', array(

    'filters'    => array('StringTrim'),

    'validators' => array(

            array('StringLength', false, array(3, 30)),

        ),

    'required'   => true,

    'label'      => 'Name',

        'size' => 30 

    ));

Now I need to prepend my form with custom html paragraph (<p> element) with custom text. How I can do this?

PS: I'm using old ZEND (Before ZF2)

PsychoX
  • 1,088
  • 4
  • 21
  • 43
  • 1
    Have a look at [this question](http://stackoverflow.com/questions/2566432/add-some-html-to-zend-forms). The second answer (the one after the chosen answer) might help you setting up a custom [`Decorator`](http://framework.zend.com/manual/1.12/en/zend.form.decorators.html) – Havelock Nov 11 '12 at 17:12

2 Answers2

2

You can insert any piece of html code in the view where you will render the form like this:

file: formView.phtml

----------
<p> Here's my text </p>

<?php echo $this->form; ?>

However, if you want the <p> block to be inside the <form> tag, I would use a viewscript decorator to achieve it.

Add something like this in your form class' init method:

$this->setDecorators(array(
        array('ViewScript', array('viewScript' => 'templates/myForm.phtml'))
    ));

And in the templates/myForm.phtml file you can render your form any way you want. Here's an example:

<?php $form = $this->element; ?>
<form action="<?php echo $form->getAction(); ?>">
      <p> Your text goes here </p>
     <?php echo $form->user; ?>
</form>

I hope I made myself clear. If you have any doubts, don't hesitate to ask

You can read more about the viewscript decorator here http://framework.zend.com/manual/1.12/en/zend.form.standardDecorators.html#zend.form.standardDecorators.viewScript

elbunuelo
  • 91
  • 2
0

check out this decorators may be helpful

$this->setDecorators(array(

           'FormElements',
           array(array('data'=>'HtmlTag'),array('tag'=>'p')),
           'Form'

   ));
Ammar Hayder Khan
  • 1,287
  • 4
  • 22
  • 49