I have the following code in IndexController.php. If I submit the form with
the value "Help's Needed!" (without the double quotes) in "Field 1", the
form will fail validation (because "Field 2" is empty), and will repopulate
"Field 1" with "Help\'s Needed!" (without the double quotes). Aren't the
slashes stripped by Zend_Form? If not, What's the best way to filter them
out? Thanks.

<?php

class IndexController extends Zend_Controller_Action
{
    public function getForm()
    {
        $form = new Zend_Form();
        $form->setAction('/test/html/')
             ->setMethod('post');
             
        $field1 = new Zend_Form_Element_Text('field1');
        $field1->setLabel('Field 1:')
               ->setRequired(true)
               ->addFilter(new Zend_Filter_StripTags())
               ->addFilter(new Zend_Filter_StringTrim())
               ->addValidator(new Zend_Validate_NotEmpty());
        
        $field2 = new Zend_Form_Element_Text('field2');
        $field2->setLabel('Field 2:')
               ->setRequired(true)
               ->addFilter(new Zend_Filter_StripTags())
               ->addFilter(new Zend_Filter_StringTrim())
               ->addValidator(new Zend_Validate_NotEmpty());
        
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Submit');
        
        $form->addElements(array(
            $field1,
            $field2,
            $submit
        ));
        
        return $form;
    }
    
    public function indexAction()
    {
        $form = $this->getForm();
        if ($this->_request->isPost())
        {
            $data = $this->_request->getPost();
            if ($form->isValid($data))
            {
                // Save form to database, etc.
                // Redirect to thank you page
            }
        }
        $this->view->form = $form;
    }
}

-- 
View this message in context: 
http://www.nabble.com/Zend_Form-and-slashes-tp16399099p16399099.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to