@@ -157,46 +185,56 @@
function createFormSection() {
var sectionHtml = `
-
-
- `;
+ `;
$('#form-container').append(sectionHtml);
- positionAddSectionButton();
+ // Add click event for the newly created section
+ $('.form-section').last().on('click', function () {
+ $('.form-section').removeClass('active');
+ $(this).addClass('active');
+ activeSection = $(this);
+ positionAddSectionButton();
+ });
+
+ positionAddSectionButton();
}
// Handle option button click
$(document).on('click', '.add-option-btn', function () {
var $section = $(this).closest('.form-section');
var optionHtml = `
-
-
- ×
-
- `;
+
+
+ ×
+
+ `;
$section.find('.options-container').append(optionHtml);
});
// Handle delete section button click
$(document).on('click', '.delete-section-icon', function () {
$(this).closest('.form-section').remove();
+ activeSection = null;
+ positionAddSectionButton();
});
// Handle delete option button click
@@ -204,11 +242,8 @@
$(this).closest('.option').remove();
});
- // Handle preview button click
- $('#preview-btn').on('click', function () {
- alert('Preview functionality is not implemented.');
- });
- $('.form-section').each(function () {
+
+ $('.form-section').each(function () {
$(this).on('click', function () {
$('.form-section').removeClass('active');
$(this).addClass('active');
@@ -222,79 +257,101 @@
positionAddSectionButton();
});
- // Handle submit button click
- $('#submit-btn').on('click', function () {
- var formData = collectFormData();
- formData['form_id'] = ;
+ $(document).ready(function () {
+ var base_url = '';
- let validation = validateFormData(formData);
- if (!validation.isValid) {
- alert(validation.message);
- return;
- }
+ $('#submit-btn').on('click', function () {
+ var formData = collectFormData();
+ formData['form_id'] = ;
- $.ajax({
- url: base_url + 'Form_controller/update_form',
- type: 'POST',
- data: { formData: formData },
- dataType: 'JSON',
- success: function (response) {
- if (response.status === 'success') {
- alert('Form updated successfully!');
+ let validation = validateFormData(formData);
+ if (!validation.isValid) {
+ alert(validation.message);
+ return;
+ }
+
+ $.ajax({
+ url: base_url + 'Form_controller/update_form',
+ type: 'POST',
+ data: { formData: formData },
+ dataType: 'JSON',
+ success: function (response) {
+ if (response.status === 'success') {
+ Swal.fire({
+ title: 'Success!',
+ text: 'Form updated successfully!',
+ icon: 'success',
+ confirmButtonText: 'OK'
+ }).then((result) => {
+ if (result.isConfirmed) {
window.location.href = base_url + 'drafts';
- } else {
- alert(response.message);
}
- },
- error: function (error) {
- alert('Error updating form!');
- console.log(error);
- }
+ });
+ } else {
+ Swal.fire({
+ title: 'Error!',
+ text: response.message,
+ icon: 'error',
+ confirmButtonText: 'OK'
+ });
+ }
+ },
+ error: function (error) {
+ Swal.fire({
+ title: 'Error!',
+ text: 'Error updating form!',
+ icon: 'error',
+ confirmButtonText: 'OK'
});
+ console.log(error);
+ }
+ });
+ });
+
+ // Collect form data function
+ function collectFormData() {
+ var formData = {
+ title: $('#form-title').val(),
+ description: $('#form-description').val(),
+ questions: []
+ };
+
+ $('.form-section').each(function () {
+ var questionData = {
+ id: $(this).data('index'),
+ text: $(this).find('.untitled-question').val(),
+ type: $(this).find('.custom-select').val(),
+ required: $(this).find('.required-toggle').is(':checked') ? 1 : 0,
+ options: []
+ };
+
+ $(this).find('.option-label').each(function () {
+ questionData.options.push($(this).val());
});
- // Collect form data function
- function collectFormData() {
- var formData = {
- title: $('#form-title').val(),
- description: $('#form-description').val(),
- questions: []
- };
+ formData.questions.push(questionData);
+ });
- $('.form-section').each(function () {
- var questionData = {
- id: $(this).data('index'),
- text: $(this).find('.untitled-question').val(),
- type: $(this).find('.custom-select').val(),
- required: $(this).find('.required-toggle').is(':checked') ? 1 : 0, // Correctly capture the required value
- options: []
- };
+ return formData;
+ }
- $(this).find('.option-label').each(function () {
- questionData.options.push($(this).val());
- });
-
- formData.questions.push(questionData);
- });
-
- return formData;
+ function validateFormData(formData) {
+ for (let question of formData.questions) {
+ if (!question.text.trim()) {
+ return { isValid: false, message: 'All questions must have text.' };
}
- 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.' };
- }
- }
+ 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 };
}
+ }
+ return { isValid: true };
+ }
+});
// Initialize
diff --git a/application/views/response_submit.php b/application/views/response_submit.php
index d708c7a..52fd183 100644
--- a/application/views/response_submit.php
+++ b/application/views/response_submit.php
@@ -34,7 +34,7 @@
}
if (isRequired && !isAnswered) {
- container.style.border = '2px solid purple';
+ container.style.border = '2px solid red';
isValid = false;
} else {
container.style.border = 'none';
diff --git a/application/views/responses_list.php b/application/views/responses_list.php
index e646e57..977bac3 100644
--- a/application/views/responses_list.php
+++ b/application/views/responses_list.php
@@ -1,17 +1,9 @@
-
-
-
-
-
-
Responses List
-
-
-
+
+
diff --git a/application/views/templates/footer.php b/application/views/templates/footer.php
index 536bd61..75de0de 100644
--- a/application/views/templates/footer.php
+++ b/application/views/templates/footer.php
@@ -12,4 +12,100 @@
],
"order": [[1, "desc"]] // Default sort by "Filled At" column (index 1) in descending order
});
+ $(document).ready(function() {
+ // Fade out flash messages after 2 seconds
+ setTimeout(function() {
+ $('.flash-message').fadeOut(1000);
+ }, 600);
+});
+$(document).ready(function() {
+ // Fade out flash messages after 2 seconds
+ setTimeout(function() {
+ $('#flash-messages .flash-message').fadeOut(1000);
+ }, 2000);
+
+ // Example function to show validation messages
+ function showError(fieldId, message) {
+ $(`#${fieldId}-error`).text(message).show();
+ }
+
+ // Example function to hide validation messages
+ function clearError(fieldId) {
+ $(`#${fieldId}-error`).text('').hide();
+ }
+
+ // Registration form validation
+ $('#register-form').submit(function(e) {
+ e.preventDefault(); // Prevent default form submission
+
+ // Clear all previous errors
+ clearError('username');
+ clearError('email');
+ clearError('password');
+ clearError('password2');
+
+ // Validate fields
+ let isValid = true;
+
+ // Example validation logic
+ if ($('input[name="username"]').val().trim() === '') {
+ showError('username', 'Username is required.');
+ isValid = false;
+ }
+
+ if ($('input[name="email"]').val().trim() === '') {
+ showError('email', 'Email is required.');
+ isValid = false;
+ }
+
+ if ($('input[name="password"]').val().trim() === '') {
+ showError('password', 'Password is required.');
+ isValid = false;
+ }
+
+ if ($('input[name="password2"]').val().trim() === '') {
+ showError('password2', 'Confirm Password is required.');
+ isValid = false;
+ } else if ($('input[name="password"]').val() !== $('input[name="password2"]').val()) {
+ showError('password2', 'Passwords do not match.');
+ isValid = false;
+ }
+
+ if (isValid) {
+ // Proceed with form submission
+ this.submit();
+ }
+ });
+
+ // Login form validation
+ $('#login-form').submit(function(e) {
+ e.preventDefault(); // Prevent default form submission
+
+ // Clear all previous errors
+ clearError('username');
+ clearError('password');
+
+ // Validate fields
+ let isValid = true;
+
+ // Example validation logic
+ if ($('input[name="username"]').val().trim() === '') {
+ showError('username', 'Username is required.');
+ isValid = false;
+ }
+
+ if ($('input[name="password"]').val().trim() === '') {
+ showError('password', 'Password is required.');
+ isValid = false;
+ }
+
+ if (isValid) {
+ // Proceed with form submission
+ this.submit();
+ }
+ });
+});
+
+
+
diff --git a/application/views/templates/forms_ui.php b/application/views/templates/forms_ui.php
index dea9bc7..b7b634a 100644
--- a/application/views/templates/forms_ui.php
+++ b/application/views/templates/forms_ui.php
@@ -9,6 +9,11 @@
+
+
+
+
+