protected function validateForm(Form $form, $request_data) { $form->bind($request_data); if (!$form->isValid()) { $msg = $form->getErrors(); if (sizeOf($msg)) { $msg = array_map(function ($message) { return $message->getMessage(); }, $msg); $msg = "\n- " . implode("\n- ", $msg); } else { $msg = "\n- " . $form->getErrorsAsString(); } $this->get('logger')->err('Erreur formulaire: ' . $msg); throw new InvalidArgumentException($msg); } }
/** * Bepaald formulier errors voor JSON response * * @param Form $form * @return array */ private function _getFormErrors(Form $form) { $errors = array(); $string = $form->getErrorsAsString(); $parts = explode('||', str_replace(array("\r", "\r\n", "\n"), '||', $string)); foreach ($parts as $key => $val) { $vals = explode(':', $val); if (count($vals) == 2 && trim(strtolower($vals[0])) == 'error') { $errors[] = trim($vals[1]); } } return $errors; }