Esempio n. 1
0
 public function indexAction()
 {
     $form = new MyProject_Form_Example_Showcases();
     $form->setAction('/example/form/index');
     if ($this->getRequest()->isPost()) {
         // get form data
         $formData = $_POST;
         // ajax validation
         if ($this->isJson) {
             // test asynchron validation
             if (isset($formData['username'])) {
                 sleep(3);
             }
             // set output mode for json only
             $this->_makeJson();
             $response = $form->processJson($formData);
             $this->_setJson($response);
             // check if all form is valid before normal process
         } else {
             // set form data
             $form->populate($formData);
             // check if all form is valid
             if ($form->isValid($formData)) {
                 // success, do stuff with your data here!
                 // i'll just do a lame redirect here
                 // if it is ajax it will redirect anyway cause _redirect handle isAjax
                 $this->_redirect('/example/form/indexvalidate');
             }
         }
     }
     $this->view->form = $form;
 }
Esempio n. 2
0
 public function indexAction()
 {
     $form = new MyProject_Form_Example_Showcases();
     $form->setAction('/example/form/index');
     $request = $this->getRequest();
     if ($request->isPost()) {
         // get form data
         $formData = $_POST;
         // ajax validation
         if ($this->isJson) {
             // test asynchron validation
             if (isset($formData['first_name'])) {
                 sleep(5);
             }
             // set output mode for json only
             $this->_makeJson();
             $response = $form->processJson($formData);
             $this->_setJson($response);
             // check if all form is valid before normal process
         } else {
             // set form data
             $form->populate($formData);
             // check if all form is valid
             if ($form->isValid($formData)) {
                 // success, do stuff with your data here!
                 // i'll just do a lame redirect here
                 /*
                 $upload = new Zend_File_Transfer_Adapter_Http();
                 $upload->setDestination('/tmp/');
                 $upload->receive();
                 */
                 die('cool');
             }
         }
     }
     $this->view->form = $form;
 }