diff --git a/application/classes/Controller/Course.php b/application/classes/Controller/Course.php index d26d85c..fe0a80b 100644 --- a/application/classes/Controller/Course.php +++ b/application/classes/Controller/Course.php @@ -131,7 +131,35 @@ class Controller_Course extends Controller_Layout { { $this->redirect('error/404'); } - $this->_edit($model); + $this->template->errors = array(); + + if ($this->request->method() === Request::POST) { + $model->values($this->request->post(), array_keys($controls)); + $model->values($this->request->post(), ['type', 'group_id']); + $model->customize(); + $validation = $model->validate_create($this->request->post()); + try + { + if ($validation->check()) + { + $model->save(); + $this->after_save($model); + } + else + { + $this->template->errors = $validation->errors('default'); + } + } + catch (ORM_Validation_Exception $e) + { + $this->template->errors = $e->errors('default'); + } + if (empty($this->template->errors)) + { + $this->redirect($this->_edit_redirect($model)); + } + } + $this->template->model = $model; } public function action_delete() diff --git a/application/classes/Model/Course.php b/application/classes/Model/Course.php index 6cad1af..842df27 100644 --- a/application/classes/Model/Course.php +++ b/application/classes/Model/Course.php @@ -54,6 +54,12 @@ class Model_Course extends ORM { 'price' => array( array('numeric') ), + 'group_id' => array( + array('numeric') + ), + 'type' => array( + array('numeric') + ), ); }