public function addSubmitAction() { $db = Env::get('db'); $db->begin(); $entity = $this->entity; $item = $entity::createNew(); $formData = new FormData($this->editFields); $formData->retrieve(); $formData->validate(function ($errors) use($formData) { $errorsJson = json_encode($errors); $formDataJson = json_encode($formData->toStringArray()); HTTP::redirect($this->url('add', ['errors' => $errorsJson, 'form' => $formDataJson])); }); $this->beforeSave($item, $formData); $item->setData($formData->getValues()); $item->save(); $this->afterSave($item); $db->commit(); HTTP::redirect($this->url()); }