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>
4

2 回答 2

2

通过使用Zend_Form_Element_Text,您可以通过执行以下操作非常简单地在表单中插入您自己的 html/文本。

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

然后将对象插入addElements数组

$this->addElements(array(

   // My other form elements

   $text,

   // My other form elements

更新:我发现了一种更简化的方法,只需将以下内容直接包含到数组中

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

结果是,

<dd id="descCharsRemaining-element">
  <p>2000 Characters Remaining</p>
</dd>
于 2013-10-25T09:30:24.803 回答
0

div 不是表单元素,我看不出它如何接受值。为此,您可以通过扩展 zend_form_element 创建新的 zend_form 元素,创建自定义装饰器并控制元素的呈现方式或编写视图脚本来替换装饰器。

于 2013-10-24T19:06:00.663 回答