0

I am trying to inset text into a html tag created using zend form.

This is my code below, excluding my actual form elements

 $this->addElements(array(

 // My other form elements

       array(
           'hidden',
           'dummy',
           array(
               'required' => false,
               'ignore' => true,
               'autoInsertNotEmptyValidator' => false,
               'decorators' => array(
                   array(
                       'HtmlTag', array(
                           'tag'  => 'div',
                           'id'   => 'DescCharsRemaining',
                           'setValue' => '
                               2000 Characters Remaining
                           '
                       )
                   )
               )
           )
       ),

       // My other form elements

I would like to add some text similar to 'setValue' but inside HtmlTag instead of a html property of the HtmlTag.

The result I get,

 <div id="DescCharsRemaining" setvalue="2000 Characters Remaining"></div>

The result i want,

 <div id="DescCharsRemaining">2000 Characters Remaining</div>
Community
  • 1
  • 1
A Star
  • 605
  • 9
  • 18

2 Answers2

2

By using Zend_Form_Element_Text you can insert your own html/text inside the form quite simply by doing the following.

$text = new Zend_Form_Element_Text('descCharsRemaining');
$text->setValue("<p>2000 Characters Remaining</p>")
     ->helper = 'formNote';

Then inserting the object into the addElements array

$this->addElements(array(

   // My other form elements

   $text,

   // My other form elements

UPDATE: I have discovered a more simplified way to do this by just including the following directly into the array

array(
  'note',
  'desc',
     array(
       'value' => '<p>2000 Characters Remaining</p>'
     ),
),

With the result being,

<dd id="descCharsRemaining-element">
  <p>2000 Characters Remaining</p>
</dd>
A Star
  • 605
  • 9
  • 18
0

A div isn't a form element, I don't see how it will accept a value. To do this you can create a new zend_form element by extending zend_form_element, create a custom decorator and control how the element is rendered or write a view script to replace the decorator.

Gavin
  • 2,123
  • 1
  • 15
  • 19