commit
This commit is contained in:
parent
b027df8f68
commit
7a58576a1d
|
@ -1,6 +0,0 @@
|
|||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
</IfModule>
|
|
@ -76,8 +76,8 @@ $query_builder = TRUE;
|
|||
$db['default'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'admin',
|
||||
'password' => 'Password',
|
||||
'username' => 'torun',
|
||||
'password' => 'thug@NIT20',
|
||||
'database' => 'google_forms',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
|
|
|
@ -9,7 +9,7 @@ $route['responses/view/(:num)'] = 'Response_submit/viewresponse/$1';
|
|||
$route['default_controller'] = 'Form_controller/index_forms';
|
||||
$route['404_override'] = '';
|
||||
$route['translate_uri_dashes'] = FALSE;
|
||||
$route['start'] = 'home/index';
|
||||
$route['start'] = 'Form_controller/index_forms';
|
||||
$route['new_form'] = 'home/create_form';
|
||||
$route['title_desc'] = 'home/title';
|
||||
$route['default_page'] = 'Form_controller/index_forms';
|
||||
|
|
|
@ -60,16 +60,33 @@ redirect('default_page');
|
|||
|
||||
// Save the edited form
|
||||
public function update_form() {
|
||||
$form_id = $this->input->post('form_id');
|
||||
$title = $this->input->post('title');
|
||||
$description = $this->input->post('description');
|
||||
$questions = $this->input->post('questions');
|
||||
$formData = $this->input->post('formData');
|
||||
|
||||
$this->Updation_model->update_form($form_id, $title, $description);
|
||||
$this->Updation_model->update_questions($form_id, $questions);
|
||||
|
||||
echo json_encode(['status' => 'success']);
|
||||
if (!$formData) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Form data is missing']);
|
||||
return;
|
||||
}
|
||||
|
||||
$form_id = $formData['form_id'];
|
||||
$title = $formData['title'];
|
||||
$description = $formData['description'];
|
||||
$questions = $formData['questions'];
|
||||
|
||||
$this->load->model('Updation_model');
|
||||
$updateStatus = $this->Updation_model->update_form_data($form_id, $title, $description, $questions);
|
||||
|
||||
if ($updateStatus) {
|
||||
echo json_encode(['status' => 'success', 'message' => 'Form updated successfully']);
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Failed to update form data']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function index_forms_draft($form_id = null) {
|
||||
$this->load->model('Frontend_model');
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ class Forms extends CI_Controller
|
|||
redirect('users/login');
|
||||
}
|
||||
|
||||
|
||||
// Load the model that handles the form data
|
||||
$this->load->model('preview_model');
|
||||
|
||||
|
@ -61,21 +60,20 @@ class Forms extends CI_Controller
|
|||
$data['questions'] = $questions;
|
||||
|
||||
$this->load->view('response_submit', $data);
|
||||
|
||||
}
|
||||
public function preview_back($form_id)
|
||||
{
|
||||
public function preview_back($form_id) {
|
||||
if (!$this->session->userdata('logged_in')) {
|
||||
// If not logged in, redirect to login page
|
||||
redirect('users/login');
|
||||
}
|
||||
|
||||
// Load the model that handles the form data
|
||||
$this->load->model('preview_model');
|
||||
|
||||
// Fetch the form details
|
||||
$form = $this->preview_model->get_form($form_id);
|
||||
|
||||
// Fetch the questions for the form
|
||||
// Fetch the questions for the form including 'is_required'
|
||||
$questions = $this->preview_model->get_questions($form_id);
|
||||
|
||||
// Fetch the options for each question
|
||||
|
@ -88,11 +86,8 @@ class Forms extends CI_Controller
|
|||
$data['questions'] = $questions;
|
||||
|
||||
$this->load->view('templates/header');
|
||||
|
||||
$this->load->view('form_preview_back', $data);
|
||||
$this->load->view('templates/footer');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,10 @@ class New_form_controller extends CI_Controller {
|
|||
public function submit_form() {
|
||||
if (!$this->session->userdata('logged_in')) {
|
||||
// If not logged in, redirect to login page
|
||||
redirect('users/login');
|
||||
echo json_encode(['status' => 'error', 'message' => 'User not logged in']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Decode the formData from the POST request
|
||||
$formData = $this->input->post('formData');
|
||||
|
||||
|
@ -20,7 +22,6 @@ class New_form_controller extends CI_Controller {
|
|||
|
||||
if ($saveStatus) {
|
||||
echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']);
|
||||
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Failed to save form data']);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class Publish_controller extends CI_Controller {
|
|||
$this->load->view('templates/footer');
|
||||
}
|
||||
|
||||
|
||||
// Method to unpublish a form
|
||||
public function unpublish_form($form_id) {
|
||||
if (!$this->session->userdata('logged_in')) {
|
||||
|
|
|
@ -26,14 +26,23 @@ class Response_submit extends CI_Controller {
|
|||
$this->load->view('templates/header');
|
||||
$this->load->view('responses_list', $data);
|
||||
$this->load->view('templates/footer');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function submit_form() {
|
||||
$this->load->model('Response_model');
|
||||
$responses = $this->input->post('responses');
|
||||
$user_id = $this->session->userdata('user_id'); // Assuming user_id is stored in session
|
||||
$form_id = $this->input->post('form_id'); // Assuming form_id is passed
|
||||
|
||||
// Insert into responses table
|
||||
$response_id = $this->Response_model->insert_response([
|
||||
'form_id' => $form_id,
|
||||
'user_id' => $user_id,
|
||||
'submitted_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
// Insert each answer into response_answers table
|
||||
foreach ($responses as $response) {
|
||||
$answered_text = '';
|
||||
|
||||
|
@ -47,27 +56,17 @@ class Response_submit extends CI_Controller {
|
|||
$answered_text = $response['answered_text'];
|
||||
}
|
||||
|
||||
// Find the max response_id for the given form_id
|
||||
$this->db->select_max('response_id');
|
||||
$this->db->where('form_id', $response['form_id']);
|
||||
$max_response_id = $this->db->get('responses')->row()->response_id;
|
||||
|
||||
// Increment the response_id by 1
|
||||
$new_response_id = $max_response_id + 1;
|
||||
|
||||
$data = [
|
||||
'form_id' => $response['form_id'],
|
||||
'user_id' => $user_id,
|
||||
'response_id' => $response_id,
|
||||
'question_id' => $response['question_id'],
|
||||
'answered_text' => $answered_text,
|
||||
'response_id' => $new_response_id,
|
||||
'submitted_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$this->Response_model->insert_response($data);
|
||||
$this->Response_model->insert_response_answer($data);
|
||||
}
|
||||
|
||||
redirect('Response_submit/view_responses/' . $response['form_id']);
|
||||
redirect('Response_submit/view_responses/' . $form_id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,10 +86,12 @@ class Response_submit extends CI_Controller {
|
|||
$this->load->model('Response_model');
|
||||
$data['response'] = $this->Response_model->get_response($response_id);
|
||||
$data['form'] = $this->Response_model->get_form_by_response($response_id); // Get form details
|
||||
$data['questions'] = $this->Response_model->get_questions_and_answers($response_id);
|
||||
$data['questions_and_answers'] = $this->Response_model->get_questions_and_answers($response_id);
|
||||
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('response_details_view', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class Form_model extends CI_Model {
|
|||
foreach ($section['options'] as $option_text) {
|
||||
$option_data = array(
|
||||
'question_id' => $question_id,
|
||||
'text' => $option_text,
|
||||
'option_text' => $option_text,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
);
|
||||
|
||||
|
|
|
@ -13,12 +13,14 @@ class Frontend_model extends CI_Model {
|
|||
return []; // Return an empty array if user_id is not available
|
||||
}
|
||||
|
||||
// Filter forms by user_id
|
||||
// Filter forms by user_id and order by created_at in descending order
|
||||
$this->db->where('user_id', $user_id); // Assuming 'user_id' is the column name in the 'forms' table
|
||||
$this->db->order_by('created_at', 'DESC'); // Order by created_at column, most recent first
|
||||
$query = $this->db->get('forms');
|
||||
|
||||
return $query->result(); // Return the result as an array of objects
|
||||
}
|
||||
|
||||
public function deleteForm($id){
|
||||
return $this->db->delete('forms', ['id' => $id]);
|
||||
}
|
||||
|
@ -30,7 +32,7 @@ class Frontend_model extends CI_Model {
|
|||
public function getforms_draft($user_id) {
|
||||
$this->db->where('is_published', 0); // Filter by unpublished forms
|
||||
$this->db->where('user_id', $user_id); // Filter by user_id
|
||||
$this->db->order_by('created_on', 'DESC'); // Sort by creation date, newest first
|
||||
$this->db->order_by('created_at', 'DESC'); // Sort by creation date, newest first
|
||||
$query = $this->db->get('forms');
|
||||
return $query->result();
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
class New_form_model extends CI_Model {
|
||||
|
||||
public function save_form_data($formId, $formData) {
|
||||
if (!$formId) {
|
||||
return false; // Handle error if formId is not valid
|
||||
if (!$formId || !isset($formData['questions'])) {
|
||||
return false; // Handle error if formId is not valid or questions are missing
|
||||
}
|
||||
|
||||
$questions_array = $formData['questions'];
|
||||
|
@ -13,26 +13,30 @@ class New_form_model extends CI_Model {
|
|||
'form_id' => $formId,
|
||||
'text' => $question['text'],
|
||||
'type' => $question['type'],
|
||||
'required' => ($question['required'] == 'true') ? 1 : 0
|
||||
'is_required' => isset($question['is_required']) && $question['is_required'] == 'true' ? 1 : 0
|
||||
];
|
||||
|
||||
$this->db->insert('questions', $questionData);
|
||||
$questionId = $this->db->insert_id(); // Get the inserted question_id
|
||||
|
||||
// Handle options for multiple-choice, checkboxes, and dropdown questions
|
||||
if ($question['type'] === 'multiple-choice' || $question['type'] === 'checkboxes' || $question['type'] === 'dropdown') {
|
||||
if (in_array($question['type'], ['multiple-choice', 'checkboxes', 'dropdown'])) {
|
||||
foreach ($question['options'] as $option) {
|
||||
if (!empty($option)) { // Avoid inserting empty options
|
||||
$optionData = [
|
||||
'question_id' => $questionId,
|
||||
'option_text' => $option
|
||||
'option_text' => $option // Ensure column name matches database schema
|
||||
];
|
||||
// Insert option into options table
|
||||
$this->db->insert('options', $optionData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true; // Return true indicating success
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
<?php
|
||||
class preview_model extends CI_Model {
|
||||
|
||||
public function get_form($form_id)
|
||||
{
|
||||
return $this->db->get_where('forms', array('id' => $form_id))->row();
|
||||
public function get_form($form_id) {
|
||||
$this->db->where('id', $form_id);
|
||||
$query = $this->db->get('forms');
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_questions($form_id)
|
||||
{
|
||||
return $this->db->get_where('questions', array('form_id' => $form_id))->result();
|
||||
public function get_questions($form_id) {
|
||||
$this->db->where('form_id', $form_id);
|
||||
$query = $this->db->get('questions');
|
||||
return $query->result(); // Ensure this returns objects with the 'is_required' field
|
||||
}
|
||||
|
||||
public function get_options($question_id)
|
||||
{
|
||||
return $this->db->get_where('options', array('question_id' => $question_id))->result();
|
||||
public function get_options($question_id) {
|
||||
$this->db->where('question_id', $question_id);
|
||||
$query = $this->db->get('options');
|
||||
return $query->result(); // Ensure this returns the options related to the question
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,9 @@ public function update_form($form_id, $data) {
|
|||
public function get_published_forms_by_user($user_id) {
|
||||
$this->db->where('user_id', $user_id);
|
||||
$this->db->where('is_published', 1);
|
||||
$this->db->order_by('id', 'DESC'); // Order by id column, most recent first
|
||||
$query = $this->db->get('forms');
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
<?php
|
||||
class Response_model extends CI_Model {
|
||||
// 888888888888888888888
|
||||
|
||||
public function insert_response($data) {
|
||||
$this->db->insert('responses', $data);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function insert_response_answer($data) {
|
||||
$this->db->insert('response_answers', $data);
|
||||
}
|
||||
|
||||
public function get_form($form_id) {
|
||||
$this->db->where('id', $form_id);
|
||||
$query = $this->db->get('forms');
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
// 888888888888888888888
|
||||
|
||||
|
||||
public function get_questions($form_id) {
|
||||
$this->db->where('form_id', $form_id);
|
||||
$query = $this->db->get('questions');
|
||||
|
@ -23,16 +31,33 @@ class Response_model extends CI_Model {
|
|||
$query = $this->db->get('options');
|
||||
return $query->result();
|
||||
}
|
||||
// 888888888888888888888
|
||||
|
||||
public function get_responses_by_form($form_id) {
|
||||
$this->db->select('responses.response_id, MAX(responses.submitted_at) as submitted_at, users.username');
|
||||
$this->db->select('responses.id as response_id, responses.submitted_at, users.username');
|
||||
$this->db->from('responses');
|
||||
$this->db->join('users', 'responses.user_id = users.id');
|
||||
$this->db->where('responses.form_id', $form_id);
|
||||
$this->db->group_by('responses.response_id, users.username');
|
||||
$query = $this->db->get();
|
||||
$responses = $query->result();
|
||||
|
||||
foreach ($responses as &$response) {
|
||||
$response->answers = $this->get_answers_by_response_id($response->response_id);
|
||||
}
|
||||
|
||||
return $responses;
|
||||
}
|
||||
|
||||
public function get_answers_by_response_id($response_id) {
|
||||
$this->db->select('response_answers.question_id, response_answers.answered_text');
|
||||
$this->db->from('response_answers');
|
||||
$this->db->where('response_answers.response_id', $response_id);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
} public function get_responses($form_id) {
|
||||
}
|
||||
// 888888888888888888888
|
||||
|
||||
public function get_responses($form_id) {
|
||||
$this->db->where('form_id', $form_id);
|
||||
$query = $this->db->get('responses');
|
||||
return $query->result();
|
||||
|
@ -41,25 +66,33 @@ class Response_model extends CI_Model {
|
|||
|
||||
// Method to get response details
|
||||
public function get_response($response_id) {
|
||||
$this->db->where('response_id', $response_id);
|
||||
$query = $this->db->get('responses');
|
||||
$this->db->select('responses.*, users.email');
|
||||
$this->db->from('responses');
|
||||
$this->db->join('users', 'responses.user_id = users.id'); // Assuming 'user_id' is the foreign key in 'responses'
|
||||
$this->db->where('responses.id', $response_id);
|
||||
$query = $this->db->get();
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
|
||||
// Method to get questions and answers for a response
|
||||
public function get_questions_and_answers($response_id) {
|
||||
$this->db->select('questions.id AS question_id, questions.text AS question_text, responses.answered_text');
|
||||
$this->db->select('questions.id AS question_id, questions.text AS question_text, response_answers.answered_text, users.email');
|
||||
$this->db->from('questions');
|
||||
$this->db->join('responses', 'questions.id = responses.question_id');
|
||||
$this->db->where('responses.response_id', $response_id);
|
||||
$this->db->join('response_answers', 'questions.id = response_answers.question_id');
|
||||
$this->db->join('responses', 'response_answers.response_id = responses.id');
|
||||
$this->db->join('users', 'responses.user_id = users.id'); // Join to get the user's email
|
||||
$this->db->where('response_answers.response_id', $response_id);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function get_form_by_response($response_id) {
|
||||
$this->db->select('forms.title, forms.description');
|
||||
$this->db->from('forms');
|
||||
$this->db->join('responses', 'forms.id = responses.form_id');
|
||||
$this->db->where('responses.response_id', $response_id);
|
||||
$this->db->where('responses.id', $response_id);
|
||||
$query = $this->db->get();
|
||||
return $query->row();
|
||||
}
|
||||
|
|
|
@ -18,34 +18,74 @@ class Updation_model extends CI_Model {
|
|||
$query = $this->db->get('options');
|
||||
return $query->result_array();
|
||||
}
|
||||
public function update_form_data($form_id, $title, $description, $questions) {
|
||||
$this->db->trans_start();
|
||||
|
||||
public function update_form($form_id, $title, $description) {
|
||||
// Update form title and description
|
||||
$this->db->where('id', $form_id);
|
||||
$this->db->update('forms', ['title' => $title, 'description' => $description]);
|
||||
}
|
||||
|
||||
public function update_questions($form_id, $questions) {
|
||||
// First, delete existing questions
|
||||
// Update questions
|
||||
$this->db->where('form_id', $form_id);
|
||||
$this->db->delete('questions');
|
||||
|
||||
// Insert new questions
|
||||
foreach ($questions as $question) {
|
||||
$this->db->insert('questions', [
|
||||
$question_data = [
|
||||
'form_id' => $form_id,
|
||||
'text' => $question['text']
|
||||
]);
|
||||
'text' => $question['text'],
|
||||
'type' => $question['type'],
|
||||
'is_required' => $question['required'] // Correctly capture the required value
|
||||
];
|
||||
$this->db->insert('questions', $question_data);
|
||||
$question_id = $this->db->insert_id();
|
||||
|
||||
if (isset($question['options'])) {
|
||||
foreach ($question['options'] as $option) {
|
||||
$this->db->insert('options', [
|
||||
foreach ($question['options'] as $option_text) {
|
||||
$option_data = [
|
||||
'question_id' => $question_id,
|
||||
'option_text' => $option
|
||||
]);
|
||||
'option_text' => $option_text
|
||||
];
|
||||
$this->db->insert('options', $option_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
return $this->db->trans_status();
|
||||
}
|
||||
|
||||
|
||||
private function update_question_options($question_id, $options) {
|
||||
// Fetch existing options for this question
|
||||
$existing_options = $this->db->where('question_id', $question_id)->get('options')->result_array();
|
||||
$existing_option_texts = array_column($existing_options, 'option_text');
|
||||
|
||||
// Insert or update options
|
||||
foreach ($options as $option_text) {
|
||||
if (in_array($option_text, $existing_option_texts)) {
|
||||
// Option already exists, no need to insert
|
||||
continue;
|
||||
}
|
||||
|
||||
// Insert new option
|
||||
$option_data = [
|
||||
'question_id' => $question_id,
|
||||
'option_text' => $option_text
|
||||
];
|
||||
$this->db->insert('options', $option_data);
|
||||
}
|
||||
|
||||
// Delete options that are no longer present
|
||||
$options_to_delete = array_diff($existing_option_texts, $options);
|
||||
if (!empty($options_to_delete)) {
|
||||
$this->db->where('question_id', $question_id);
|
||||
$this->db->where_in('option_text', $options_to_delete);
|
||||
$this->db->delete('options');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,66 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Google Forms</title>
|
||||
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
|
||||
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
|
||||
|
||||
</head>
|
||||
|
||||
<body style = "background-color: rgb(240,235,248);" >
|
||||
<nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);" >
|
||||
<div class="container" style="background-color: rgb(103, 58, 183);">
|
||||
<?php if ($this->session->userdata('logged_in')): ?>
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>Form_controller/index_forms">Google Forms</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div id="navbar">
|
||||
<ul class="nav navbar-nav">
|
||||
|
||||
<!-- <li><a href="<?php echo base_url(); ?>home/index3">Home</a></li> -->
|
||||
<li><a href="<?php echo base_url(); ?>Publish_controller/list_user_published_forms">Published Forms</a></li>
|
||||
<!-- <li><a href="<?php echo base_url(); ?>">Responses</a></li> -->
|
||||
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<?php if (!$this->session->userdata('logged_in')): ?>
|
||||
<li><a href="<?php echo base_url(); ?>users/login">Login</a></li>
|
||||
<li><a href="<?php echo base_url(); ?>users/register">Register</a></li>
|
||||
<?php endif; ?>
|
||||
<?php if ($this->session->userdata('logged_in')): ?>
|
||||
<li><a href="<?php echo base_url(); ?>home/title">Create Form</a></li>
|
||||
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
|
||||
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container">
|
||||
<?php if ($this->session->flashdata('user_registered')): ?>
|
||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_registered') . '</p>'; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php if ($this->session->flashdata('login_failed')): ?>
|
||||
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
<?php if ($this->session->flashdata('user_loggedout')): ?>
|
||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div></div>
|
|
@ -9,7 +9,7 @@
|
|||
</div>
|
||||
<?php endif; ?>
|
||||
<h3>
|
||||
List of Forms
|
||||
Drafts
|
||||
</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
@ -33,7 +33,7 @@
|
|||
href="<?php echo base_url('forms/preview/' . $row->id); ?>"><?php echo $row->title; ?></a>
|
||||
</td>
|
||||
<td><?php echo $row->description; ?></td>
|
||||
<td><?php echo $row->created_on; ?></td>
|
||||
<td><?php echo $row->created_at; ?></td>
|
||||
<td>
|
||||
<a href="<?php echo base_url('Form_controller/edit_form/' . $row->id); ?>"
|
||||
class="btn btn-success btn-sm">Edit</a>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
href="<?php echo base_url('forms/preview/' . $row->id); ?>"><?php echo $row->title; ?></a>
|
||||
</td>
|
||||
<td><?php echo $row->description; ?></td>
|
||||
<td><?php echo $row->created_on; ?></td>
|
||||
<td><?php echo $row->created_at; ?></td>
|
||||
<td>
|
||||
<?php echo ($row->is_published ? 'Published' : 'Draft'); ?>
|
||||
</td>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/styles.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/jquery-ui.css">
|
||||
|
||||
<style>
|
||||
/* Include your styles here */
|
||||
</style>
|
||||
|
@ -18,12 +19,11 @@
|
|||
<button id="preview-btn" class="btn btn-info"><i class="fas fa-eye"></i></button>
|
||||
<input type="text" id="form-title" class="form-control" value="<?php echo $form['title']; ?>">
|
||||
<input type="text" id="form-description" class="form-control" value="<?php echo $form['description']; ?>">
|
||||
|
||||
<button id="add-section-btn" class="btn btn-primary">+</button>
|
||||
</div>
|
||||
<div id="form-container">
|
||||
<?php foreach ($questions as $question): ?>
|
||||
<div class="form-section" data-index="<?php echo $question['id']; ?>">
|
||||
<div class="form-section" data-index="<?php echo $question['id']; ?>" data-type="<?php echo $question['type']; ?>">
|
||||
<div class="header-row">
|
||||
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"><?php echo $question['text']; ?></textarea>
|
||||
<select class="custom-select">
|
||||
|
@ -34,7 +34,7 @@
|
|||
<option value="dropdown" <?php echo $question['type'] == 'dropdown' ? 'selected' : ''; ?>>Dropdown</option>
|
||||
</select>
|
||||
<label class="toggle-switch">
|
||||
<input type="checkbox" class="required-toggle" <?php echo $question['required'] ? 'checked' : ''; ?>>
|
||||
<input type="checkbox" class="required-toggle" <?php echo $question['is_required'] ? 'checked' : ''; ?>>
|
||||
<span class="slider"></span>
|
||||
</label>
|
||||
<span class="delete-section-icon"><i class="fas fa-trash-alt"></i></span>
|
||||
|
@ -52,28 +52,28 @@
|
|||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<!-- Show or hide the "Add Option" button based on question type -->
|
||||
<?php if ($question['type'] === 'multiple-choice' || $question['type'] === 'checkboxes' || $question['type'] === 'dropdown'): ?>
|
||||
<button class="btn btn-secondary add-option-btn">Add Option</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<button id="submit-btn" class="btn btn-success" style="margin-left: 240px; margin-top: 20px">Submit</button>
|
||||
</div>
|
||||
|
||||
<script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>
|
||||
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
|
||||
<script src="<?php echo base_url('assets/js/jquery-ui.js'); ?>"></script>
|
||||
<!-- <script src="<?php echo base_url('assets/js/edit.js'); ?>"></script> -->
|
||||
<!-- <script src="<?php echo base_url('assets/js/scripts.js'); ?>"></script> -->
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function() {
|
||||
var base_url = '<?php echo base_url(); ?>';
|
||||
|
||||
// Add section button functionality
|
||||
$('#add-section-btn').on('click', function() {
|
||||
var sectionHtml = `
|
||||
<div class="form-section">
|
||||
<div class="form-section" data-type="">
|
||||
<div class="header-row">
|
||||
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"></textarea>
|
||||
<select class="custom-select">
|
||||
|
@ -89,9 +89,8 @@
|
|||
</label>
|
||||
<span class="delete-section-icon"><i class="fas fa-trash-alt"></i></span>
|
||||
</div>
|
||||
<div class="options-container">
|
||||
</div>
|
||||
<button class="btn btn-secondary add-option-btn">Add Option</button>
|
||||
<div class="options-container"></div>
|
||||
<button class="btn btn-secondary add-option-btn" style="display: none;">Add Option</button>
|
||||
</div>
|
||||
`;
|
||||
$('#form-container').append(sectionHtml);
|
||||
|
@ -118,11 +117,27 @@
|
|||
$(this).closest('.form-section').remove();
|
||||
});
|
||||
|
||||
// Show/Hide "Add Option" button based on question type
|
||||
$(document).on('change', '.custom-select', function() {
|
||||
var type = $(this).val();
|
||||
var $section = $(this).closest('.form-section');
|
||||
if (type === 'multiple-choice' || type === 'checkboxes' || type === 'dropdown') {
|
||||
$section.find('.add-option-btn').show();
|
||||
} else {
|
||||
$section.find('.add-option-btn').hide();
|
||||
}
|
||||
}).trigger('change'); // Trigger change to apply to existing sections
|
||||
// Submit button functionality
|
||||
$('#submit-btn').on('click', function() {
|
||||
var formData = collectFormData();
|
||||
formData['form_id'] = <?php echo $form['id']; ?>;
|
||||
|
||||
let validation = validateFormData(formData);
|
||||
if (!validation.isValid) {
|
||||
alert(validation.message);
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: base_url + 'Form_controller/update_form',
|
||||
type: 'POST',
|
||||
|
@ -131,6 +146,7 @@
|
|||
success: function(response) {
|
||||
if (response.status === 'success') {
|
||||
alert('Form updated successfully!');
|
||||
window.location.href = base_url + 'Form_controller/index_forms_draft';
|
||||
} else {
|
||||
alert(response.message);
|
||||
}
|
||||
|
@ -155,7 +171,7 @@
|
|||
id: $(this).data('index'),
|
||||
text: $(this).find('.untitled-question').val(),
|
||||
type: $(this).find('.custom-select').val(),
|
||||
required: $(this).find('.required-toggle').is(':checked'),
|
||||
required: $(this).find('.required-toggle').is(':checked') ? 1 : 0, // Correctly capture the required value
|
||||
options: []
|
||||
};
|
||||
|
||||
|
@ -168,9 +184,23 @@
|
|||
|
||||
return formData;
|
||||
}
|
||||
function validateFormData(formData) {
|
||||
for (let question of formData.questions) {
|
||||
if (!question.text.trim()) {
|
||||
return { isValid: false, message: 'All questions must have text.' };
|
||||
}
|
||||
if ((question.type === 'multiple-choice' || question.type === 'checkboxes' || question.type === 'dropdown') && question.options.length === 0) {
|
||||
return { isValid: false, message: 'All options-based questions must have at least one option.' };
|
||||
}
|
||||
for (let option of question.options) {
|
||||
if (!option.trim()) {
|
||||
return { isValid: false, message: 'All options must have text.' };
|
||||
}
|
||||
}
|
||||
}
|
||||
return { isValid: true };
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,3 +1,75 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Form Preview - Google Forms</title>
|
||||
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/form_preview_back.css">
|
||||
<style>
|
||||
body {
|
||||
background-color: rgb(240, 235, 248);
|
||||
}
|
||||
.container {
|
||||
margin-top: 30px;
|
||||
}
|
||||
.form-header {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
margin-left: 240px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
border-top: 10px solid rgb(103, 58, 183);
|
||||
width: 56%;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.form-header h2, .form-header h4 {
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
}
|
||||
.form-header h4 {
|
||||
color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.form-section {
|
||||
background-color: white;
|
||||
margin-bottom: 30px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
}
|
||||
.question-section {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.question-label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.options-container {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.option {
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.option input[type="checkbox"] {
|
||||
margin-right: 10px;
|
||||
width: 16px; /* Adjust size of checkbox */
|
||||
height: 16px; /* Adjust size of checkbox */
|
||||
}
|
||||
.option input[type="radio"] {
|
||||
margin-right: 10px;
|
||||
width: 16px; /* Adjust size of radio button */
|
||||
height: 16px; /* Adjust size of radio button */
|
||||
}
|
||||
.option label {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="form-header">
|
||||
<h2><?php echo $form->title; ?></h2>
|
||||
|
@ -19,7 +91,7 @@
|
|||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php elseif ($question->type == 'checkbox'): ?>
|
||||
<?php elseif ($question->type == 'checkboxes'): ?>
|
||||
<div class="options-container">
|
||||
<?php foreach ($question->options as $option): ?>
|
||||
<div class="option">
|
||||
|
@ -50,4 +122,5 @@
|
|||
|
||||
<a href="<?php echo base_url('Publish_controller/publish_form/'.$form->id); ?>" class="btn btn-success" style="margin-top: 20px; position: relative; left: 240px;">Publish</a>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Form Preview - Google Forms</title>
|
||||
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/form_preview_back.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="form-header">
|
||||
<h2><?php echo $form->title; ?></h2>
|
||||
|
@ -19,7 +29,7 @@
|
|||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php elseif ($question->type == 'checkbox'): ?>
|
||||
<?php elseif ($question->type == 'checkboxes'): ?>
|
||||
<div class="options-container">
|
||||
<?php foreach ($question->options as $option): ?>
|
||||
<div class="option">
|
||||
|
@ -50,4 +60,5 @@
|
|||
|
||||
<a href="<?php echo base_url('Publish_controller/list_user_published_forms'); ?>" class="btn btn-success" style="margin-top: 20px; position: relative; left: 240px;">Back</a>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,15 +1,28 @@
|
|||
|
||||
<div class="container">
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Response Details</title>
|
||||
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/response_details_view.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="form-header">
|
||||
<h2><?php echo $form->title; ?></h2>
|
||||
<h4><?php echo $form->description; ?></h4>
|
||||
<h4 class="form-description"><?php echo $form->description; ?></h4>
|
||||
<p class="submitted-at">Submitted At: <?php echo $response->submitted_at; ?></p>
|
||||
<p class="user-email">User Email: <?php echo $response->email; ?></p>
|
||||
</div>
|
||||
<?php foreach ($questions as $question): ?>
|
||||
<?php foreach ($questions_and_answers as $question): ?>
|
||||
<div class="form-section">
|
||||
<div class="question-section">
|
||||
<input type="text" class="form-control question-label" value="<?php echo $question->question_text; ?>" disabled>
|
||||
<textarea class="form-control" disabled><?php echo $question->answered_text; ?></textarea>
|
||||
<p class="form-control question-label"><?php echo $question->question_text; ?></p>
|
||||
<div class="form-control" disabled><?php echo $question->answered_text; ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -5,14 +5,24 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Form Preview - Google Forms</title>
|
||||
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
||||
<style>
|
||||
body { background-color: rgb(240, 235, 248); }
|
||||
.container { margin-top: 30px; }
|
||||
.form-section { background-color: white; width: 56%; margin-bottom: 30px; margin-left: 240px; padding: 20px; position: relative; align-items: center; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
|
||||
.form-header { background-color: white; padding: 20px; margin-bottom: 10px; margin-left: 240px; border-radius: 10px 10px 0 0; display:flex ;flex-direction: column; justify-content: space-between; align-items: left; position: relative; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); border-top: 10px solid rgb(103, 58, 183); width: 56%; }
|
||||
.form-section h2 { text-align: center; margin-bottom: 30px; }
|
||||
.form-section .question-section { margin-bottom: 20px; }
|
||||
</style>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/response_submit.css">
|
||||
|
||||
<script>
|
||||
function validateForm() {
|
||||
let isValid = true;
|
||||
document.querySelectorAll('.question-container').forEach(function(container) {
|
||||
let isRequired = container.dataset.required === '1';
|
||||
let inputs = container.querySelectorAll('input[type="text"], textarea, select, input[type="radio"]:checked, input[type="checkbox"]:checked');
|
||||
if (isRequired && inputs.length === 0) {
|
||||
container.style.border = '2px solid red';
|
||||
isValid = false;
|
||||
} else {
|
||||
container.style.border = 'none';
|
||||
}
|
||||
});
|
||||
return isValid;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
@ -20,14 +30,14 @@
|
|||
<h2><?php echo $form->title; ?></h2>
|
||||
<h4><?php echo $form->description; ?></h4>
|
||||
</div>
|
||||
<form action="<?php echo base_url('response_submit/submit_form'); ?>" method="post">
|
||||
<form action="<?php echo base_url('response_submit/submit_form'); ?>" method="post" onsubmit="return validateForm();">
|
||||
<input type="hidden" name="form_id" value="<?php echo $form->id; ?>">
|
||||
<div class="form-section">
|
||||
<?php foreach ($questions as $question): ?>
|
||||
<div class="question-section">
|
||||
<div class="question-container" data-required="<?php echo $question->is_required; ?>">
|
||||
<input type="hidden" name="responses[<?php echo $question->id; ?>][question_id]" value="<?php echo $question->id; ?>">
|
||||
<input type="hidden" name="responses[<?php echo $question->id; ?>][form_id]" value="<?php echo $form->id; ?>">
|
||||
<label><?php echo $question->text; ?></label>
|
||||
<label class="<?php echo $question->is_required ? 'required-field' : ''; ?>"><?php echo $question->text; ?></label>
|
||||
<?php if ($question->type == 'multiple-choice'): ?>
|
||||
<?php foreach ($question->options as $option): ?>
|
||||
<div class="option">
|
||||
|
@ -35,7 +45,7 @@
|
|||
<label><?php echo $option->option_text; ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php elseif ($question->type == 'checkbox'): ?>
|
||||
<?php elseif ($question->type == 'checkboxes'): ?>
|
||||
<?php foreach ($question->options as $option): ?>
|
||||
<div class="option">
|
||||
<input type="checkbox" name="responses[<?php echo $question->id; ?>][options][]" value="<?php echo $option->option_text; ?>">
|
||||
|
@ -56,9 +66,8 @@
|
|||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success" style="margin-top: 20px; position: relative; left: 240px;">Submit</button>
|
||||
<button type="submit" class="btn btn-success" style="display: block; margin: 20px auto 20px 240px;">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<div></div>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#basetable1').DataTable();
|
||||
$('#basetable1').DataTable({
|
||||
// "pagingType": "full_numbers"
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</script>
|
||||
|
|
|
@ -1,320 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Google Form Clone</title>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/styles.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/jquery-ui.css">
|
||||
<style>
|
||||
.navbar-custom {
|
||||
background-color: rgb(103, 58, 183);
|
||||
color: white;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.navbar-custom .navbar-brand {
|
||||
color: white;
|
||||
font-size: 18px; /* Adjust font size for navbar links */
|
||||
}
|
||||
|
||||
.navbar-custom .navbar-nav > li > a {
|
||||
color: white;
|
||||
font-size: 16px; /* Adjust font size for navbar links */
|
||||
}
|
||||
|
||||
/* Additional styling for submit button */
|
||||
#submit-btn {
|
||||
margin-top: 20px;
|
||||
float: left; /* Align button to the left */
|
||||
clear: both; /* Clear float to ensure proper layout */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse navbar-custom">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index2">Google Forms</a>
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index3">Home</a>
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index1">About</a>
|
||||
</div>
|
||||
<div id="navbar">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>users/logout">Logout</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
<div class="form-header">
|
||||
<button id="preview-btn" class="btn btn-info"><i class="fas fa-eye"></i></button>
|
||||
<h2>Untitled Form</h2>
|
||||
<button id="add-section-btn" class="btn btn-primary">+</button>
|
||||
</div>
|
||||
<div id="form-container"></div>
|
||||
|
||||
<!-- Submit button -->
|
||||
<button class="btn btn-success" style="margin-left: 240px; margin-top: 20px">Submit</button>
|
||||
</div>
|
||||
|
||||
<script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>
|
||||
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
|
||||
<script src="<?php echo base_url('assets/js/jquery-ui.js'); ?>"></script>
|
||||
<script src="<?php echo base_url('assets/js/scripts.js'); ?>"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
$(document).ready(function() {
|
||||
let index = 1;
|
||||
let activeSection = null;
|
||||
|
||||
// Add option function
|
||||
function addOption(type, container) {
|
||||
let optionIndex = container.children().length + 1;
|
||||
let optionHtml;
|
||||
if (type === 'multiple-choice' || type === 'checkboxes') {
|
||||
optionHtml = `
|
||||
<div class="option">
|
||||
<input type="${type === 'multiple-choice' ? 'radio' : 'checkbox'}" disabled>
|
||||
<input type="text" class="form-control option-label" value="Option ${optionIndex}">
|
||||
<span class="delete-option-icon">×</span>
|
||||
</div>
|
||||
`;
|
||||
} else if (type === 'dropdown') {
|
||||
optionHtml = `
|
||||
<div class="option">
|
||||
<input type="text" class="form-control option-label" value="Option ${optionIndex}">
|
||||
<span class="delete-option-icon">×</span>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
container.append(optionHtml);
|
||||
}
|
||||
|
||||
// Form section function
|
||||
function createFormSection() {
|
||||
let newSection = `
|
||||
<div class="form-section" data-index="${index}">
|
||||
<div class="header-row">
|
||||
${index === 1 ? '<div class="violet-border"></div>' : ''}
|
||||
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"></textarea>
|
||||
<select class="custom-select">
|
||||
<option value="short-answer">Short Answer</option>
|
||||
<option value="paragraph">Paragraph</option>
|
||||
<option value="multiple-choice">Multiple Choice</option>
|
||||
<option value="checkboxes">Checkboxes</option>
|
||||
<option value="dropdown">Dropdown</option>
|
||||
</select>
|
||||
<label class="toggle-switch">
|
||||
<input type="checkbox" class="required-toggle">
|
||||
<span class="slider"></span>
|
||||
</label>
|
||||
<span class="delete-section-icon"><i class="fas fa-trash-alt"></i></span>
|
||||
</div>
|
||||
<div class="options-container"></div>
|
||||
</div>
|
||||
`;
|
||||
$('#form-container').append(newSection);
|
||||
index++;
|
||||
|
||||
positionAddSectionButton();
|
||||
}
|
||||
|
||||
function positionAddSectionButton() {
|
||||
if (activeSection) {
|
||||
let position = activeSection.position();
|
||||
let buttonWidth = $('#add-section-btn').outerWidth();
|
||||
let buttonHeight = $('#add-section-btn').outerHeight();
|
||||
|
||||
$('#add-section-btn').css({
|
||||
position: 'absolute',
|
||||
left: position.left - buttonWidth - 47 + 'px',
|
||||
top: position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Event handler is triggered
|
||||
// creates a new form section;sets it as active;repositions the add section button
|
||||
$('#add-section-btn').on('click', function() {
|
||||
createFormSection();
|
||||
$('.form-section').removeClass('active');
|
||||
activeSection = $('.form-section').last();
|
||||
activeSection.addClass('active');
|
||||
positionAddSectionButton();
|
||||
});
|
||||
|
||||
// It updates the options container based on the selected type, adding the necessary input fields or buttons.
|
||||
$(document).on('change', '.custom-select', function() {
|
||||
let type = $(this).val();
|
||||
let container = $(this).closest('.form-section').find('.options-container');
|
||||
container.empty();
|
||||
|
||||
$(this).closest('.form-section').find('.add-option-btn').remove();
|
||||
|
||||
if (type === 'short-answer') {
|
||||
container.append('<input type="text" class="form-control" disabled placeholder="Short answer text">');
|
||||
} else if (type === 'paragraph') {
|
||||
container.append('<textarea class="form-control" disabled placeholder="Paragraph text"></textarea>');
|
||||
} else {
|
||||
addOption(type, container);
|
||||
$(this).closest('.form-section').append('<button class="btn btn-secondary add-option-btn">Add Option</button>');
|
||||
}
|
||||
});
|
||||
|
||||
// add option event handler
|
||||
// adds a new option to the options container and updates the option numbers
|
||||
$(document).on('click', '.add-option-btn', function() {
|
||||
let type = $(this).closest('.form-section').find('.custom-select').val();
|
||||
let container = $(this).closest('.form-section').find('.options-container');
|
||||
addOption(type, container);
|
||||
// refreshOptionNumbers(container);
|
||||
});
|
||||
|
||||
// removes the section;updates the active section;repositions add section button
|
||||
$(document).on('click', '.delete-section-icon', function() {
|
||||
let section = $(this).closest('.form-section');
|
||||
let prevSection = section.prev('.form-section');
|
||||
let nextSection = section.next('.form-section');
|
||||
section.remove();
|
||||
if (section.hasClass('active')) {
|
||||
activeSection = null;
|
||||
}
|
||||
if (prevSection.length > 0) {
|
||||
prevSection.find('.delete-section-icon').appendTo(prevSection.find('.form-section'));
|
||||
activeSection = prevSection;
|
||||
} else if (nextSection.length > 0) {
|
||||
nextSection.find('.delete-section-icon').appendTo(nextSection.find('.form-header'));
|
||||
activeSection = nextSection;
|
||||
}
|
||||
|
||||
positionAddSectionButton();
|
||||
});
|
||||
|
||||
// delete option
|
||||
$(document).on('click', '.delete-option-icon', function() {
|
||||
let option = $(this).closest('.option');
|
||||
let container = option.closest('.options-container');
|
||||
option.remove();
|
||||
K });
|
||||
|
||||
// Event handler for required toggle button
|
||||
$(document).on('click', '.required-toggle', function() {
|
||||
$(this).closest('.form-section').toggleClass('required');
|
||||
});
|
||||
|
||||
// Preview button functionality
|
||||
$('#preview-btn').on('click', function() {
|
||||
let previewWindow = window.open('', '_blank');
|
||||
let previewContent = `
|
||||
<html>
|
||||
<head>
|
||||
<title>Form Preview</title>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body { background-color: rgb(240, 235, 248); }
|
||||
.container { margin-top: 30px; }
|
||||
.form-section {background-color: white;width: 56%;margin-bottom: 30px;margin-left: 240px;padding: 20px;position: relative;align-items: center;border-radius: 10px;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
|
||||
.form-header {background-color: white;padding: 20px;margin-bottom: 10px;margin-left: 240px;border-radius: 10px 10px 0 0;display: flex;justify-content: space-between;align-items: center; position: relative;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);border-top: 10px solid rgb(103, 58, 183);width: 56%; }
|
||||
.form-section h2 { text-align: center; margin-bottom: 30px; }
|
||||
.form-section .question-section { margin-bottom: 20px; } /* Add margin-bottom to the question section */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="form-header">
|
||||
<h2>Untitled Form</h2>
|
||||
</div>
|
||||
`;
|
||||
$('.form-section').each(function() {
|
||||
previewContent += '<div class="form-section">';
|
||||
previewContent += '<div class="question-section">';
|
||||
previewContent += '<textarea class="form-control question-label" disabled>' + $(this).find('.untitled-question').val() + '</textarea>';
|
||||
previewContent += '</div>';
|
||||
let type = $(this).find('.custom-select').val();
|
||||
let optionsContainer = $(this).find('.options-container');
|
||||
|
||||
if (type === 'multiple-choice') {
|
||||
optionsContainer.find('.option').each(function() {
|
||||
previewContent += `
|
||||
<div class="option">
|
||||
<input type="radio" name="option-${index}">
|
||||
<label>${$(this).find('.option-label').val()}</label>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
} else if (type === 'checkboxes') {
|
||||
optionsContainer.find('.option').each(function() {
|
||||
previewContent += `
|
||||
<div class="option">
|
||||
<input type="checkbox">
|
||||
<label>${$(this).find('.option-label').val()}</label>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
} else if (type === 'short-answer') {
|
||||
previewContent += '<input type="text" class="form-control" placeholder="Short answer text">';
|
||||
} else if (type === 'paragraph') {
|
||||
previewContent += '<textarea class="form-control" placeholder="Paragraph text"></textarea>';
|
||||
} else if (type === 'dropdown') {
|
||||
let dropdownHtml = '<select class="form-control">';
|
||||
optionsContainer.find('.option .option-label').each(function() {
|
||||
dropdownHtml += `<option>${$(this).val()}</option>`;
|
||||
});
|
||||
dropdownHtml += '</select>';
|
||||
previewContent += dropdownHtml;
|
||||
}
|
||||
previewContent += '</div>';
|
||||
});
|
||||
previewContent += `
|
||||
<button class="btn btn-success" style="margin-left: 240px; margin-top: 20px">Submit</button>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
previewWindow.document.write(previewContent);
|
||||
previewWindow.document.close();
|
||||
});
|
||||
|
||||
// Activate the section;repositions add section button
|
||||
$(document).on('click', '.form-section', function() {
|
||||
$('.form-section').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
activeSection = $(this);
|
||||
positionAddSectionButton();
|
||||
});
|
||||
|
||||
$('#form-container').sortable({
|
||||
placeholder: 'ui-state-highlight',
|
||||
start: function (event, ui) {
|
||||
ui.placeholder.height(ui.item.height());
|
||||
},
|
||||
stop: function (event, ui) {
|
||||
positionAddSectionButton();
|
||||
}
|
||||
});
|
||||
|
||||
$('#form-container').disableSelection();
|
||||
});
|
||||
i have shared with you my html file as well as the js file,
|
||||
i want you to update the js file in such a way that once i click the submit button in the forms ui section i want them to get updated in the database through post data.
|
||||
each of the question text or the options i create and the type of question such as dropdown or checkbox,try to enclose every data under an active form ,in a similar way as you fetched all the information to show in the preview window.
|
||||
|
||||
for each of the question text in each div created , i want to save in the text colomn in the questions table and for the type of question that is dropdown or multiple choice or checkbox etc i want to save them as 1,2,3,4 or 5 in the type colomn in the questions table and if the required button is selected it should reflect in the required colomn in the table as 0 or 1, for the options created in each of the div tag or the question tag should be saved in the text colomn in the options table.
|
||||
so that i can retreive the data when required.
|
||||
i want you also to create all the controllers and the models and the view required to perform the above task,i have created a login page after authorization the user is able to create the form
|
||||
so with respect to that particular users id , all the above contents should be updated in the database
|
||||
i will explain you the structure of my database
|
||||
have also created a database in the phpmyadmin as google_forms wherein i currently have 4 tables as users,forms,questions,options
|
||||
in the users table id,username,email,password,created_at where id isthe primary key .
|
||||
The forms table has id,user_id as the foreign key which is refernced to the id from users table,created_at and description colomn.
|
||||
questions table has id as the primary key,form_id as the foreign key which is referenced to the id from the forms table ,text,type,required ,created_at.
|
||||
and the options table has id as the primary key ,question_id as the foreign key which is referenced to the id from the questions table.
|
||||
finally i want a updation in my js file and html file as suggested
|
||||
and i want all the controller and models to perform this task in the codeigniter
|
|
@ -1,320 +0,0 @@
|
|||
**********MODEL****************
|
||||
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Form_model extends CI_Model {
|
||||
|
||||
public function save_form($form_data) {
|
||||
$this->db->trans_start();
|
||||
|
||||
foreach ($form_data as $section) {
|
||||
$question_data = array(
|
||||
'form_id' => $section['form_id'],
|
||||
'text' => $section['text'],
|
||||
'type' => $section['type'],
|
||||
'required' => $section['required'],
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
);
|
||||
|
||||
$this->db->insert('questions', $question_data);
|
||||
$question_id = $this->db->insert_id();
|
||||
|
||||
foreach ($section['options'] as $option_text) {
|
||||
$option_data = array(
|
||||
'question_id' => $question_id,
|
||||
'text' => $option_text,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
);
|
||||
|
||||
$this->db->insert('options', $option_data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
if ($this->db->trans_status() === FALSE) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
********************Controller**********************
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Form extends CI_Controller {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->model('Form_model');
|
||||
}
|
||||
|
||||
public function submit() {
|
||||
$form_data = json_decode($this->input->raw_input_stream, true);
|
||||
|
||||
if ($this->Form_model->save_form($form_data)) {
|
||||
$response = array('status' => 'success', 'message' => 'Form submitted successfully.');
|
||||
} else {
|
||||
$response = array('status' => 'error', 'message' => 'Error submitting form.');
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
}
|
||||
}
|
||||
***********UPDATED HTML*************************
|
||||
### Updated HTML
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Google Form Clone</title>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/styles.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/jquery-ui.css">
|
||||
<style>
|
||||
.navbar-custom {
|
||||
background-color: rgb(103, 58, 183);
|
||||
color: white;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.navbar-custom .navbar-brand {
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.navbar-custom .navbar-nav>li>a {
|
||||
color: white;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#submit-btn {
|
||||
margin-top: 20px;
|
||||
float: left;
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse navbar-custom">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index2">Google Forms</a>
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index3">Home</a>
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index1">About</a>
|
||||
</div>
|
||||
<div id="navbar">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<a class="navbar-brand" href="<?php echo base_url(); ?>users/logout">Logout</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
<div class="form-header">
|
||||
<button id="preview-btn" class="btn btn-info"><i class="fas fa-eye"></i></button>
|
||||
<h2>Untitled Form</h2>
|
||||
<button id="add-section-btn" class="btn btn-primary">+</button>
|
||||
</div>
|
||||
<div id="form-container"></div>
|
||||
|
||||
<input type="hidden" id="form-id" value="YOUR_FORM_ID"> <!-- Ensure to set the form ID dynamically -->
|
||||
<button id="submit-btn" class="btn btn-success">Submit</button>
|
||||
</div>
|
||||
|
||||
<script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>
|
||||
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
|
||||
<script src="<?php echo base_url('assets/js/jquery-ui.js'); ?>"></script>
|
||||
<script src="<?php echo base_url('assets/js/scripts.js'); ?>"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#add-section-btn').on('click', function() {
|
||||
let newSection = `
|
||||
<div class="form-section">
|
||||
<input type="text" class="untitled-question" placeholder="Untitled Question">
|
||||
<select class="custom-select">
|
||||
<option value="text">Text</option>
|
||||
<option value="multiple_choice">Multiple Choice</option>
|
||||
</select>
|
||||
<input type="checkbox" class="required-toggle"> Required
|
||||
<div class="options-container">
|
||||
<button class="add-option-btn btn btn-secondary">Add Option</button>
|
||||
</div>
|
||||
</div>`;
|
||||
$('#form-container').append(newSection);
|
||||
});
|
||||
|
||||
$(document).on('click', '.add-option-btn', function() {
|
||||
let optionInput = '<input type="text" class="option-label" placeholder="Option">';
|
||||
$(this).before(optionInput);
|
||||
});
|
||||
|
||||
$('#submit-btn').on('click', function() {
|
||||
let formData = collectFormData();
|
||||
|
||||
$.ajax({
|
||||
url: '<?php echo base_url(); ?>form/submit',
|
||||
type: 'POST',
|
||||
data: JSON.stringify(formData),
|
||||
contentType: 'application/json; charset=utf-8',
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
alert('Form submitted successfully!');
|
||||
console.log(response);
|
||||
},
|
||||
error: function(error) {
|
||||
alert('Error submitting form!');
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function collectFormData() {
|
||||
let formData = [];
|
||||
let formId = $('#form-id').val();
|
||||
|
||||
$('.form-section').each(function() {
|
||||
let questionText = $(this).find('.untitled-question').val();
|
||||
let type = $(this).find('.custom-select').val();
|
||||
let required = $(this).find('.required-toggle').is(':checked');
|
||||
let options = [];
|
||||
|
||||
$(this).find('.option-label').each(function() {
|
||||
options.push($(this).val());
|
||||
});
|
||||
|
||||
formData.push({
|
||||
form_id: formId,
|
||||
text: questionText,
|
||||
type: type,
|
||||
required: required,
|
||||
options: options
|
||||
});
|
||||
});
|
||||
|
||||
return formData;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
*************************************88*************************
|
||||
new Controller
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Questions extends CI_Controller {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
// Load necessary models and libraries here
|
||||
$this->load->model('Form_model'); // Load your Form_model
|
||||
}
|
||||
|
||||
public function save() {
|
||||
// Handle AJAX post data
|
||||
$form_data = $this->input->post('form_data'); // Assuming your AJAX post sends 'form_data'
|
||||
|
||||
if (!empty($form_data)) {
|
||||
foreach ($form_data as $section) {
|
||||
$question_data = array(
|
||||
'form_id' => $section['form_id'],
|
||||
'text' => $section['text'],
|
||||
'type' => $section['type'],
|
||||
'required' => $section['required'],
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
);
|
||||
|
||||
$question_id = $this->Form_model->save_question($question_data);
|
||||
|
||||
// Save options for this question
|
||||
foreach ($section['options'] as $option_text) {
|
||||
$option_data = array(
|
||||
'question_id' => $question_id,
|
||||
'text' => $option_text,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
);
|
||||
|
||||
$this->Form_model->save_option($option_data);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(array('success' => true));
|
||||
} else {
|
||||
echo json_encode(array('success' => false));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
******************************newMODEL**********
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Form_model extends CI_Model {
|
||||
|
||||
public function save_question($question_data) {
|
||||
$this->db->insert('questions', $question_data);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function save_option($option_data) {
|
||||
$this->db->insert('options', $option_data);
|
||||
}
|
||||
|
||||
}
|
||||
******************JAVASCRIPT************updatead
|
||||
function collectFormData() {
|
||||
let formData = [];
|
||||
let formId = $('#form-id').val();
|
||||
|
||||
$('.form-section').each(function() {
|
||||
let questionText = $(this).find('.untitled-question').val();
|
||||
let type = $(this).find('.custom-select').val();
|
||||
let required = $(this).find('.required-toggle').is(':checked');
|
||||
let options = [];
|
||||
|
||||
$(this).find('.option-label').each(function() {
|
||||
options.push($(this).val());
|
||||
});
|
||||
|
||||
formData.push({
|
||||
form_id: formId,
|
||||
text: questionText,
|
||||
type: type,
|
||||
required: required,
|
||||
options: options
|
||||
});
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: 'Questions/save', // Endpoint to handle saving questions
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { form_data: formData },
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
alert('Form data saved successfully!');
|
||||
// Handle success actions
|
||||
} else {
|
||||
alert('Failed to save form data.');
|
||||
// Handle failure actions
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
alert('Error: ' + error);
|
||||
// Handle error actions
|
||||
}
|
||||
});
|
||||
}
|
|
@ -7,9 +7,14 @@
|
|||
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/styles.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/2.0.8/css/dataTables.bootstrap.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/jquery-ui.css">
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/2.1.0/css/dataTables.dataTables.css">
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.4/js/dataTables.bootstrap4.min.js"></script>
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
body { background-color: rgb(240, 235, 248); }
|
||||
.container { margin-top: 30px; }
|
||||
.form-header {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
margin-left: 240px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
border-top: 10px solid rgb(103, 58, 183);
|
||||
width: 56%;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.form-header h2 { margin: 0; }
|
||||
.form-header h4 { color: rgba(0, 0, 0, 0.5); }
|
||||
.form-section {
|
||||
background-color: white;
|
||||
margin-bottom: 30px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
}
|
||||
.question-section {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.question-label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.options-container {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.option {
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.option input[type="checkbox"] {
|
||||
margin-right: 10px;
|
||||
width: 16px; /* Adjust size of checkbox */
|
||||
height: 16px; /* Adjust size of checkbox */
|
||||
}
|
||||
.option input[type="radio"] {
|
||||
margin-right: 10px;
|
||||
width: 16px; /* Adjust size of radio button */
|
||||
height: 16px; /* Adjust size of radio button */
|
||||
}
|
||||
.option label {
|
||||
margin: 0;
|
||||
}
|
|
@ -112,3 +112,5 @@ a.pagination-link{
|
|||
#basetable1 th, #basetable1 td {
|
||||
border: 1px solid #3333336c; /* Darker border color for table cells */
|
||||
}
|
||||
/* Custom DataTables pagination styles */
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
.form-header {
|
||||
margin-bottom: 20px;
|
||||
text-align: left;
|
||||
}
|
||||
.form-description, .submitted-at, .user-email {
|
||||
color: rgba(0, 0, 0, 0.5); /* Transparent text */
|
||||
margin-bottom: 10px;
|
||||
text-align: left; /* Align text left */
|
||||
display: block; /* Ensure each element is a block element */
|
||||
width: 100%; /* Ensure each element takes the full width of the container */
|
||||
padding-left: 0; /* Ensure no padding is affecting alignment */
|
||||
}
|
||||
|
||||
.form-section {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.question-section {
|
||||
border: 1px solid #ddd;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
text-align: left;
|
||||
}
|
||||
.container {
|
||||
width: 65%; /* Or any specific width */
|
||||
/* text-align: left; Ensure the container itself is aligned left */
|
||||
padding: 0; /* Ensure no padding is affecting alignment */
|
||||
margin: 0 auto; /* Center the container if needed */
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
body { background-color: rgb(240, 235, 248); }
|
||||
.container { margin-top: 30px; }
|
||||
.form-header {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
margin-left: 240px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
border-top: 10px solid rgb(103, 58, 183);
|
||||
width: 56%;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.form-header h2 { margin: 0; }
|
||||
.form-header h4 { color: rgba(0, 0, 0, 0.5); }
|
||||
.form-section {
|
||||
background-color: white;
|
||||
width: 56%;
|
||||
margin-left: 240px;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.question-container {
|
||||
border: 1px solid #ddd;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.option {
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.option input[type="radio"],
|
||||
.option input[type="checkbox"] {
|
||||
margin-right: 10px;
|
||||
}
|
||||
.required-field::after {
|
||||
content: '*';
|
||||
color: red;
|
||||
margin-left: 5px;
|
||||
}
|
||||
.form-section {
|
||||
background-color: white;
|
||||
margin-bottom: 30px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
}
|
||||
.question-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
|
@ -216,3 +216,10 @@ input:checked + .slider:before {
|
|||
.body_header_bg{
|
||||
background-color: rgb(240,235,248);
|
||||
}
|
||||
table a:not(.btn) {
|
||||
color: blue !important;
|
||||
}
|
||||
|
||||
table a:not(.btn):hover {
|
||||
color: darkblue !important;
|
||||
}
|
||||
|
|
|
@ -217,27 +217,33 @@ function addOption(type, container) {
|
|||
|
||||
function collectFormData() {
|
||||
var formData = {
|
||||
questions:[]
|
||||
questions: []
|
||||
};
|
||||
|
||||
$('.form-section').each(function() {
|
||||
var questionType = $(this).find('.custom-select').val();
|
||||
var questionData = {
|
||||
text: $(this).find('.untitled-question').val(),
|
||||
type: $(this).find('.custom-select').val(),
|
||||
type: questionType,
|
||||
required: $(this).find('.required-toggle').is(':checked'),
|
||||
options: []
|
||||
};
|
||||
|
||||
// Only add options if the question type supports them
|
||||
if (questionType === 'multiple-choice' || questionType === 'checkboxes' || questionType === 'dropdown') {
|
||||
$(this).find('.option-label').each(function() {
|
||||
questionData.options.push($(this).val());
|
||||
});
|
||||
}
|
||||
|
||||
formData.questions.push(questionData);
|
||||
});
|
||||
console.log(formData);
|
||||
|
||||
// console.log(formData);
|
||||
return formData;
|
||||
}
|
||||
|
||||
|
||||
function validateFormData(formData) {
|
||||
for (let question of formData.questions) {
|
||||
if (!question.text.trim()) {
|
||||
|
@ -254,7 +260,6 @@ function addOption(type, container) {
|
|||
}
|
||||
return { isValid: true };
|
||||
}
|
||||
|
||||
$('#submit-btn').on('click', function() {
|
||||
let formData = collectFormData();
|
||||
console.log(formData);
|
||||
|
@ -273,7 +278,8 @@ function addOption(type, container) {
|
|||
success: function(response) {
|
||||
if (response.status === 'success') {
|
||||
alert('Form submitted successfully!');
|
||||
console.log(response);
|
||||
// Redirect to Form_controller/index_forms
|
||||
window.location.href = base_url + 'Form_controller/index_forms';
|
||||
} else {
|
||||
alert(response.message);
|
||||
console.log(response);
|
||||
|
@ -281,6 +287,7 @@ function addOption(type, container) {
|
|||
},
|
||||
error: function(error) {
|
||||
alert('Error submitting form!');
|
||||
window.location.href = base_url + 'Form_controller/index_forms';
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue