Esempio n. 1
0
 public function testGetErrorsHonorsElementsBelongTo()
 {
     $subForm = new \Zend\Form\SubForm();
     $subForm->setElementsBelongTo('foo[bar]');
     $subForm->addElement('text', 'test')->test->setRequired(true);
     $this->form->addSubForm($subForm, 'sub');
     $data = array('foo' => array('bar' => array('test' => '')));
     $this->form->isValid($data);
     $codes = $this->form->getErrors();
     $this->assertFalse(empty($codes['foo']['bar']['test']));
 }
Esempio n. 2
0
 public function saveAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $message = array("success" => 0, "message" => "Please Correct the Errors Below!");
     if ($this->_addForm->isValid($_POST)) {
         //As everything is ok, save it...
         $task = $this->_dataTable->createRow();
         $task->name = $this->_addForm->getElement("name")->getValue();
         $task->description = $this->_addForm->getElement("desc")->getValue();
         $time = $this->_addForm->getElement("end_date")->getValue();
         if (!empty($time)) {
             $task->end_date = date("Y-m-d", strtotime($time));
         }
         $task->status = Task::STATUS_OPEN;
         $task->save();
         $message["success"] = 1;
         $message["message"] = "Task is saved successfully! Wait For Redirection!";
     } else {
         $message["errors"] = $this->_addForm->getErrors();
     }
     echo json_encode($message);
 }
Esempio n. 3
0
 function getErrors($name = null, $suppressArrayNotation = false)
 {
     $e = parent::getErrors($name, $suppressArrayNotation);
     if ($e) {
         foreach ($e as &$el) {
             if ($el) {
                 foreach ($el as &$el_1) {
                     $el_1 = $this->translateError($el_1);
                 }
             }
         }
     }
     return $e;
 }
 /**
  * Main method
  * @param string The form object
  * @param string Name of the element
  * @return boolean
  */
 public function isFormElementError(Zend_Form $form, $element)
 {
     return isset($form->getErrors($element));
 }
Esempio n. 5
0
 /**
  * Helper function to merge different types of error.
  *
  * @param \Zend_Form $form    The form.
  * @param string     $element The name of the element.
  *
  * @return array
  */
 public static function mergeErrors($form, $elementName)
 {
     $elementErrors = $form->getErrors($elementName);
     $element = $form->getElement($elementName);
     if ($element && method_exists($element, 'getErrorMessages')) {
         $elementCustomErrors = $element->getErrorMessages();
     }
     if (!is_array($elementErrors)) {
         $elementErrors = array();
     }
     if (!is_array($elementCustomErrors)) {
         $elementCustomErrors = array();
     }
     return array_merge($elementErrors, $elementCustomErrors);
 }