added response preview fixed issue with response links
This commit is contained in:
parent
9fa0f3abea
commit
8572bbf644
|
@ -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' => '',
|
||||
|
|
|
@ -145,23 +145,17 @@ class Forms extends CI_Controller
|
|||
}
|
||||
|
||||
public function publish_form($form_id) {
|
||||
|
||||
// Update is_published to 1
|
||||
$this->Form_model->update_form($form_id, ['is_published' => 1]);
|
||||
|
||||
// Generate a unique link
|
||||
$response_link = base_url("forms/respond/" . $form_id);
|
||||
|
||||
// Prepare data for the view
|
||||
$data = [];
|
||||
$data['response_link'] = $response_link;
|
||||
$data['forms'] = $this->Form_model->get_all_forms();
|
||||
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('forms/myforms',$data);
|
||||
$this->load->view('templates/footer');
|
||||
|
||||
// Update is_published to 1 and set the response link
|
||||
$this->Form_model->update_form($form_id, [
|
||||
'is_published' => 1,
|
||||
'response_link' => $response_link
|
||||
]);
|
||||
|
||||
// Redirect to the list_user_forms function
|
||||
redirect('forms/list_user_published_forms');
|
||||
}
|
||||
|
||||
public function respond($form_id){
|
||||
|
@ -214,13 +208,39 @@ class Forms extends CI_Controller
|
|||
|
||||
// View a specific response
|
||||
public function view_response($response_id) {
|
||||
// Get the response details
|
||||
$data['response'] = $this->Form_model->get_response($response_id);
|
||||
$data['form'] = $this->Form_model->get_form($data['response']->form_id);
|
||||
if (empty($data['response'])) {
|
||||
show_404();
|
||||
}
|
||||
|
||||
// Get the form details using the form ID from the response
|
||||
$form_id = $data['response']->form_id;
|
||||
$data['form'] = $this->Form_model->get_form($form_id);
|
||||
|
||||
// Get the questions and their options for the form
|
||||
$data['questions'] = $this->Form_model->get_questions_by_form_id($form_id);
|
||||
foreach ($data['questions'] as &$question) {
|
||||
$question->options = $this->Form_model->get_options_by_question_id($question->question_id);
|
||||
}
|
||||
|
||||
|
||||
// Load the views
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('forms/view_response', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
}
|
||||
|
||||
public function list_user_published_forms() {
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
$data['forms'] = $this->Form_model->get_published_forms_by_user($user_id);
|
||||
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('forms/user_forms', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -178,5 +178,13 @@ class Form_model extends CI_Model {
|
|||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_published_forms_by_user($user_id) {
|
||||
$this->db->where('user_id', $user_id);
|
||||
$this->db->where('is_published', 1); // Ensure only published forms are retrieved
|
||||
$query = $this->db->get('forms');
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,3 +26,4 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
@ -7,7 +7,6 @@
|
|||
<th>Form Title</th>
|
||||
<th>Published</th>
|
||||
<th>Created At</th>
|
||||
<th>Response Links</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -17,13 +16,6 @@
|
|||
<td><a href="<?= base_url() ?>forms/preview/<?=$form->form_id?> "><?= htmlspecialchars($form->title, ENT_QUOTES, 'UTF-8') ?></a></td>
|
||||
<td><?= ($form->is_published == 0)?'No':'Yes'?></td>
|
||||
<td><?php echo date('Y-m-d H:i:s', strtotime($form->created_at)); ?></td>
|
||||
<td>
|
||||
<?php if (isset($response_link) && $form->is_published == 1): ?>
|
||||
<a href="<?= $response_link ?>">Response link</a>
|
||||
<?php else: ?>
|
||||
Not Published
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
<div class="page_layout">
|
||||
<h1>Your Forms</h1>
|
||||
<div style="margin: 0 10%;">
|
||||
<h1>Published Forms</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Form Title</th>
|
||||
<th>Created At</th>
|
||||
<th>Response Links</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($forms)) : ?>
|
||||
<?php foreach ($forms as $form) : ?>
|
||||
<tr>
|
||||
<td><a href="<?= base_url('forms/list_form_responses/' . $form->form_id) ?>"><?= htmlspecialchars($form->title, ENT_QUOTES, 'UTF-8') ?></a></td>
|
||||
<td><a href="<?= base_url() ?>forms/list_form_responses/<?=$form->form_id?>"><?= htmlspecialchars($form->title, ENT_QUOTES, 'UTF-8') ?></a></td>
|
||||
<td><?= date('Y-m-d H:i:s', strtotime($form->created_at)) ?></td>
|
||||
<td><a href="<?= $form->response_link ?>"><?= $form->response_link ?></a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<tr>
|
||||
<td colspan="2">No forms found.</td>
|
||||
<td colspan="3">No forms found.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
|
|
|
@ -17,17 +17,16 @@
|
|||
</div>
|
||||
<br>
|
||||
<?php
|
||||
$answer_text = '';
|
||||
$answer_texts = [];
|
||||
foreach ($response->answers as $answer) {
|
||||
if ($answer->question_id == $question->question_id) {
|
||||
$answer_text = htmlspecialchars($answer->answer_text, ENT_QUOTES, 'UTF-8');
|
||||
break;
|
||||
$answer_texts[] = htmlspecialchars($answer->answer_text, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if ($question->question_type == 'paragraph') : ?>
|
||||
<div class="question-box_short-answer">
|
||||
<textarea name="responses[<?= $question->question_id ?>]" placeholder="Paragraph" readonly><?= $answer_text ?></textarea>
|
||||
<textarea name="responses[<?= $question->question_id ?>]" placeholder="Paragraph" readonly><?= implode("\n", $answer_texts) ?></textarea>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div id="options-container">
|
||||
|
@ -35,10 +34,10 @@
|
|||
<?php foreach ($question->options as $optionIndex => $option) : ?>
|
||||
<div class="question-box_option-block" id="option-template" data-option_id="<?= htmlspecialchars($option->option_id, ENT_QUOTES, 'UTF-8') ?>" >
|
||||
<?php if ($question->question_type == 'multiple-choice') : ?>
|
||||
<input type="radio" id="option-<?= $optionIndex ?>" name="responses[<?= $question->question_id ?>]" value="<?= htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8') ?>" <?= ($answer_text == htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8')) ? 'checked' : '' ?> readonly>
|
||||
<input type="radio" id="option-<?= $optionIndex ?>" name="responses[<?= $question->question_id ?>]" value="<?= htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8') ?>" <?= (in_array(htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8'), $answer_texts)) ? 'checked' : '' ?> readonly>
|
||||
<label for="option-<?= $optionIndex ?>"><?= htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8') ?></label>
|
||||
<?php elseif ($question->question_type == 'checkbox') : ?>
|
||||
<input type="checkbox" id="option-<?= $optionIndex ?>" name="responses[<?= $question->question_id ?>][]" value="<?= htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8') ?>" <?= (strpos($answer_text, htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8')) !== false) ? 'checked' : '' ?> readonly>
|
||||
<input type="checkbox" id="option-<?= $optionIndex ?>" name="responses[<?= $question->question_id ?>][]" value="<?= htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8') ?>" <?= (in_array(htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8'), $answer_texts)) ? 'checked' : '' ?> readonly>
|
||||
<label for="option-<?= $optionIndex ?>"><?= htmlspecialchars($option->option_text, ENT_QUOTES, 'UTF-8') ?></label>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue