/** * (non-PHPdoc) * @see \Micro\Application\Controller\Crud::postValidate() */ protected function postValidate(Form $form, EntityInterface $item, array $data) { if (isset($data['name']) && $data['name'] && isset($data['countryId']) && $data['countryId']) { $m = new \Brands\Model\Table\Brands(); $where = array('name = ?' => $data['name'], 'countryId = ?' => $data['countryId'], 'typeId = ?' => $data['typeId']); if ($item->getId()) { $where['id <> ?'] = $item->getId(); } if ($m->fetchRow($where)) { $form->countryId->addError('Тази марка и тип съществува за тази държава'); $form->markAsError(); } } if ($data['statusId'] && !$data['statusDate']) { $form->statusDate->addError('Дата на статуса е задължителна'); $form->markAsError(); } if (!$data['statusId'] && $data['statusDate']) { $form->statusId->addError('Статус на марката е задължителен'); $form->markAsError(); } }
public function wizzardAction() { $form = new Form(package_path('Brands', 'Resources/forms/admin/wizzard.php')); if ($this->request->isPost()) { $post = $this->request->getPost(); $post = Utils::arrayMapRecursive('trim', $post); if (isset($post['btnBack'])) { return new RedirectResponse(route(\null, ['action' => 'index', 'id' => \null])); } $form->isValid($post); if (isset($post['name']) && $post['name'] && isset($post['countryId']) && $post['countryId']) { $m = new \Brands\Model\Table\Brands(); foreach ($post['countryId'] as $countryId) { $where = array('name = ?' => $post['name'], 'countryId = ?' => $countryId, 'typeId = ?' => $post['typeId']); if ($m->fetchRow($where)) { $form->countryId->addError('Тази марка и тип съществува за някои от избраните държави'); $form->markAsError(); break; } } } if (!$form->hasErrors()) { $redirectResponse = new RedirectResponse(route(\null, ['action' => 'index', 'id' => \null])); try { $post = Utils::arrayMapRecursive('trim', $post, true); $this->getModel()->multipleInsert($post); return $redirectResponse->withFlash('Информацията е записана'); } catch (\Exception $e) { return $redirectResponse->withFlash($e->getMessage(), 'danger'); } } } $this->view->assign('form', $form); }