2
votes

I've created a composite form but the problem is that it doesn't send attribs to my rendered form.

    class My_View_Helper_NameElement extends Zend_View_Helper_FormElement {
    protected $xhtml = '';
    public function nameElement($name, $value = null, $attribs= null) {
        $helper = new Zend_View_Helper_FormText();
        $helper->setView($this->view);
        $this->xhtml .= $helper->formText($name . '[first_name]', '', array());
        $this->xhtml .= $helper->formText($name . '[last_name]', '', array());
        return $this->xhtml;
        }
    }
    
setAttrib in following code doesn't send the class
    $this->xhtml .= $helper->formText($name . '[first_name]', '', array();
    $this->xhtml .= $helper->formText($name . '[last_name]', '', array());
1
what do you see when you echo $name?Lenin Raj Rajasekaran
I get: <dt id="name-label"> <label for="name" class="required">Name:</label> </dt> <dd id="name-element"> <input type="text" name="name[first_name]" id="name-first_name" value=""> <input type="text" name="name[last_name]" id="name-last_name" value=""> </dd>eneepo
I'm expecting to be: <dt id="name-label"> <label for="name" class="required">Name:</label> </dt> <dd id="name-element"> <input type="text" name="name[first_name]" id="name-first_name" value="" class="text mini"> <input type="text" name="name[last_name]" id="name-last_name" value="" class="text mini"> </dd> it doesn't render class='text mini'eneepo

1 Answers

2
votes

Change your parent class like the following.

$this->xhtml .= $helper->formText($name . '[first_name]', '', array());

to

$this->xhtml .= $helper->formText($name . '[first_name]', '', array(), $attribs);

The above should work. If it doesn't, just use the following code. It will work.

$this->xhtml .= $helper->formText($name . '[first_name]', '', array(),
array('class' => 'text mini');