Hello guys

Using zf 1.6.1.

In my controller i have the following:

                public function indexAction(){
                        $this->view->form = $this->loadForm()->render();
                }
                
                
                /**
                 * Loads the contact form
                 *
                 * @return Zend_Form
                 */
                protected function loadForm(){
                        $form = new Zend_Form();
                        $form->setAction('/contact/submit')->setMethod('post');
                        $form->setAttrib('id', 'contact')->setAttrib('class', 
'form');
                        
                        $name = $form->createElement('text', 'name');
                        
                        $name->addValidator(new Zend_Validate_Alnum())
                                 ->addValidator(new 
Zend_Validate_StringLength(3, 50))
                                 ->setRequired(true)
                                 ->addFilter(new Zend_Filter_StringTrim())
                                 ->addFitler(new Zend_Filter_StripTags());
                
                        $form->addElement($name);
                        $form->addElement(new Zend_Form_Element_Text('email'));
                        $form->addElement(new 
Zend_Form_Element_Text('telephone'));
                        $form->addElement(new 
Zend_Form_Element_Textarea('comment'));

                        return $form;
                }

I am having two problems with the above code. First of all, it is throwing
an error when i use addFilter on the text element returned by
zend_form::createElement:

"Fatal error: Uncaught exception 'Zend_Form_Element_Exception' with message
'Method addFitler does not exist'"

So if i comment out the addFilter invocations, i do not get any exceptions,
yet the form is rendering without labels - the documentation says the
htmlTag and label helpers (as well as error and viewhelper) are applied by
default. Yet the above code returns the following markup:

<form id="contact" enctype="application/x-www-form-urlencoded"
action="/contact/submit" method="post" class="form"><dl class="zend_form">
<dt>&nbsp;</dt>
<dd>
<input type="text" name="name" id="name" value=""></dd>
<dt>&nbsp;</dt>
<dd>
<input type="text" name="email" id="email" value=""></dd>
<dt>&nbsp;</dt>
<dd>
<input type="text" name="telephone" id="telephone" value=""></dd>
<dt>&nbsp;</dt>
<dd>
<textarea name="comment" id="comment" rows="24"
cols="80"></textarea></dd></dl></form>

Why are the labels not being applied, and what am i doing wrong with the
addFilter?
-- 
View this message in context: 
http://www.nabble.com/Form-element-throwing-exception-when-using-addfilter%2C-and-not-rendering-correctly-tp19964937p19964937.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to