diff --git a/application/config/database.php b/application/config/database.php index de9475a..e8ab51e 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -76,8 +76,8 @@ $query_builder = TRUE; $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', - 'username' => 'root', - 'password' => '', + 'username' => 'jostheta', + 'password' => 'Pa$$w0rd', 'database' => 'gforms', 'dbdriver' => 'mysqli', 'dbprefix' => '', diff --git a/application/controllers/Forms.php b/application/controllers/Forms.php index f6580e2..f8120ea 100644 --- a/application/controllers/Forms.php +++ b/application/controllers/Forms.php @@ -223,7 +223,7 @@ class Forms extends CI_Controller $form_id = $this->input->post('form_id'); $responses = $this->input->post('responses'); - $questions = $this->Form_model->get_questions_by_form_id($form_id); // Assuming you have a method to get questions by form_id + $questions = $this->Form_model->get_questions_by_form_id($form_id); $errors = []; @@ -234,9 +234,9 @@ class Forms extends CI_Controller } if (!empty($errors)) { - $this->session->set_flashdata('errors', $errors); - $this->session->set_flashdata('responses', $responses); // Persisting responses - redirect('forms/respond_form/' . $form_id); // Redirect back to the form + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(['success' => false, 'errors' => $errors])); } else { if ($this->Form_model->save_responses($form_id, $responses)) { $this->output @@ -250,6 +250,30 @@ class Forms extends CI_Controller } } + + public function respond_form($form_id) { + $this->load->model('Form_model'); + + $form = $this->Form_model->get_form_by_id($form_id); + $questions = $this->Form_model->get_questions_by_form_id($form_id); + + $responses = $this->session->flashdata('responses'); + $errors = $this->session->flashdata('errors'); + $success = $this->session->flashdata('success'); + $error = $this->session->flashdata('error'); + + $data = [ + 'form' => $form, + 'questions' => $questions, + 'responses' => $responses, + 'errors' => $errors, + 'success' => $success, + 'error' => $error, + ]; + + $this->load->view('forms/respond_form', $data); + } + // List all forms of the current logged-in user public function list_user_forms() { diff --git a/application/views/forms/respond_form.php b/application/views/forms/respond_form.php index fb828f7..3bc302e 100644 --- a/application/views/forms/respond_form.php +++ b/application/views/forms/respond_form.php @@ -7,6 +7,15 @@