public function action_edit($id = null) { is_null($id) and Response::redirect('contact'); if (!($contact = Model_Contact::find($id))) { Session::set_flash('error', 'Could not find contact #' . $id); Response::redirect('contact'); } $val = Model_Contact::validate('edit'); if ($val->run()) { $contact->fullname = Input::post('fullname'); $contact->message = Input::post('message'); $contact->email = Input::post('email'); $contact->phone = Input::post('phone'); $contact->available = Input::post('available'); if ($contact->save()) { Session::set_flash('success', 'Updated contact #' . $id); Response::redirect('contact'); } else { Session::set_flash('error', 'Could not update contact #' . $id); } } else { if (Input::method() == 'POST') { $contact->fullname = $val->validated('fullname'); $contact->message = $val->validated('message'); $contact->email = $val->validated('email'); $contact->phone = $val->validated('phone'); $contact->available = $val->validated('available'); Session::set_flash('error', $val->error()); } $this->template->set_global('contact', $contact, false); } $this->template->title = "Contacts"; $this->template->content = View::forge('contact/edit'); }
public function action_index() { $errors = null; if (Input::post('confirm')) { foreach ($this->fields as $field) { Session::set_flash($field, Input::post($field)); } } $val = Model_Contact::validate(); if (Security::check_token()) { if ($val->run()) { Response::redirect("teachers/contact/confirm"); } else { $errors = $val->error(); } } $view = View::forge("teachers/contact/index"); $this->template->content = $view; }