Hello,

I am trying to submit a zend form, have it run through validation, and then
echo back any errors, etc that the validation finds.

The form is being pushed into the content area using isXmlHttpRequest check
and layout disabled for isXmlHttpRequest requests.

////////////////////////////

class FormsConroller extends CustomController
{
        function preDispatch()
        (
                        if($this->_request->isXmlHttpRequest())
                                { $this->getHelper('layout')->disableLayout(); }
        }
        
        
        function myform()
        {
                        // Build form
                 $infoform = new My_Forms_InforequestForm(array(
                        'id' => "addinfoForm",
                        'action' => '/main/forms/inforequest'
        //              'onsubmit' => "return false;"
                        ));
                        $infoform->_rec_array = $this->rec_array;
                        $infoform->buildForm();
        
        
               if ($infoform->isValid($this->_request->getPost()))
               {
                  // process submitted info
               }
        }

}

////////////////////////////

My Form looks like this:

class My_Forms_InforequestForm extends Zend_Form{

        public $_rec_array;

        public function init()
    {
                $this->addPrefixPath('My_Helper', 'My/Helper/', 'element');
    }


    public function buildForm()
    {
        $this->addElement('text', 'purpose', array(
            'filters' => array('StringTrim'),
            'validators' => array(
                'Alpha',
                array('StringLength', false, array(2, 50)),
            ),
            'required' => true,
            'label' => 'Purpose: ',
                        'size' => 45,
        ) );

        $this->addElement('submit', 'Submit Request', array(
            'required' => false,
            'ignore' => true,
            'label' => 'Submit Request',
                        'class' => 'button'
        ));

        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
            array('Description', array('placement' => 'prepend')),
            'Form'
        ), 'infoForm');
    }
}





Problems are:

1) When i submit, it always makes it into the processing check ( if
($infoform->isValid($this->_request->getPost())) ) so it runs through the
insert/processing code i have in there

2) After submission, the form does not change. No error messages are shown,
BUT i can see them in firebug viewing the returned html.

Any help would be greatly appreciated as I think I may be branching too far
from the built in functionality of this and dont want to get into writing
custom form handling if ZF can do it built in.

Should I be using a regular POST for the form or something else?

Thank you.
-- 
View this message in context: 
http://www.nabble.com/Zend_Form-isXmlHttpRequest-and-Validation-tp21094592p21094592.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to