v4
This commit is contained in:
parent
d0ad1dc6cd
commit
cab661dbb4
@ -54,3 +54,7 @@ a:hover {
|
||||
.table {
|
||||
border: 1px solid var(--light-gray);
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
@ -8,21 +8,11 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
surveyForm.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const name = document.getElementById('name').value.trim();
|
||||
const email = document.getElementById('email').value.trim();
|
||||
const message = document.getElementById('message').value.trim();
|
||||
|
||||
if (name === '' || email === '' || message === '') {
|
||||
alert('Please fill out all fields.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validateEmail(email)) {
|
||||
alert('Please enter a valid email address.');
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData(this);
|
||||
const emailInput = document.getElementById('email');
|
||||
if (emailInput) {
|
||||
formData.append('email', emailInput.value);
|
||||
}
|
||||
|
||||
fetch('submit_feedback.php', {
|
||||
method: 'POST',
|
||||
@ -31,10 +21,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
formContainer.classList.add('hidden');
|
||||
successMessage.classList.remove('hidden');
|
||||
if (formContainer) {
|
||||
formContainer.classList.add('hidden');
|
||||
}
|
||||
if (successMessage) {
|
||||
successMessage.classList.remove('hidden');
|
||||
}
|
||||
} else {
|
||||
alert('An error occurred: ' + data.error);
|
||||
alert('An error occurred: ' + (data.error || 'Unknown error'));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@ -48,3 +42,4 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
return re.test(String(email).toLowerCase());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
BIN
assets/pasted-20251007-214249-09f8d1f8.png
Normal file
BIN
assets/pasted-20251007-214249-09f8d1f8.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 142 KiB |
@ -0,0 +1 @@
|
||||
ALTER TABLE feedback_submissions MODIFY COLUMN message TEXT NULL;
|
||||
@ -10,10 +10,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$survey_id = trim($_POST['survey_id'] ?? '');
|
||||
$answers = $_POST['answers'] ?? [];
|
||||
|
||||
if (empty($name) || empty($email) || empty($survey_id) || empty($answers)) {
|
||||
if (empty($name) || empty($survey_id) || empty($answers)) {
|
||||
$response['error'] = 'Please fill out all fields.';
|
||||
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$response['error'] = 'Invalid email format.';
|
||||
} else {
|
||||
$pdo = db();
|
||||
try {
|
||||
@ -27,6 +25,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Insert into survey_answers
|
||||
$answer_stmt = $pdo->prepare("INSERT INTO survey_answers (submission_id, question_id, answer_text) VALUES (?, ?, ?)");
|
||||
foreach ($answers as $question_id => $answer_text) {
|
||||
if (is_array($answer_text)) {
|
||||
$answer_text = implode(', ', $answer_text);
|
||||
}
|
||||
if (!empty($answer_text)) {
|
||||
$answer_stmt->execute([$submission_id, $question_id, $answer_text]);
|
||||
}
|
||||
@ -58,3 +59,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
|
||||
15
survey.php
15
survey.php
@ -54,12 +54,12 @@ require_once 'templates/header.php';
|
||||
<input type="hidden" name="survey_id" value="<?= $survey_id ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name" class="form-label">Full Name</label>
|
||||
<label for="name" class="form-label">Name</label>
|
||||
<input type="text" id="name" name="name" class="form-control" value="<?= isset($_SESSION['username']) ? htmlspecialchars($_SESSION['username']) : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email" class="form-label">Email Address</label>
|
||||
<input type="email" id="email" name="email" class="form-control" value="<?= isset($_SESSION['email']) ? htmlspecialchars($_SESSION['email']) : '' ?>" required>
|
||||
<input type="email" id="email" name="email" class="form-control" value="<?= isset($_GET['email']) ? htmlspecialchars($_GET['email']) : '' ?>" disabled required>
|
||||
</div>
|
||||
|
||||
<?php foreach ($questions as $question): ?>
|
||||
@ -78,12 +78,15 @@ require_once 'templates/header.php';
|
||||
</div>
|
||||
<?php elseif ($question['question_type'] === 'multiple-choice'): ?>
|
||||
<?php $options = explode(',', $question['options']); ?>
|
||||
<select name="answers[<?= $question['id'] ?>]" class="form-control" required>
|
||||
<option value="">Select an option</option>
|
||||
<div class="checkbox-group">
|
||||
<?php foreach ($options as $option): ?>
|
||||
<option value="<?= htmlspecialchars(trim($option)) ?>"><?= htmlspecialchars(trim($option)) ?></option>
|
||||
<?php $option = trim($option); ?>
|
||||
<div class="checkbox-item">
|
||||
<input type="checkbox" id="option-<?= htmlspecialchars($option) ?>-<?= $question['id'] ?>" name="answers[<?= $question['id'] ?>][]" value="<?= htmlspecialchars($option) ?>">
|
||||
<label for="option-<?= htmlspecialchars($option) ?>-<?= $question['id'] ?>"><?= htmlspecialchars($option) ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@ -1,36 +1,59 @@
|
||||
<?php
|
||||
$pageTitle = isset($pageTitle) ? $pageTitle : 'SurveySphere';
|
||||
$description = isset($description) ? $description : 'Create and manage surveys with ease.';
|
||||
$canonical_url = "https://" . $_SERVER['HTTP_HOST'] . strtok($_SERVER["REQUEST_URI"], '?');
|
||||
|
||||
// Determine if the current page is the survey page
|
||||
$isSurveyPage = basename($_SERVER['PHP_SELF']) == 'survey.php';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= isset($pageTitle) ? htmlspecialchars($pageTitle) : 'Flatlogic' ?></title>
|
||||
<meta name="description" content="<?= isset($description) ? htmlspecialchars($description) : 'Provide your valuable feedback to help us improve.' ?>">
|
||||
<title><?= $pageTitle ?></title>
|
||||
<meta name="description" content="<?= $description ?>">
|
||||
<link rel="canonical" href="<?= $canonical_url ?>" />
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
<header class="header">
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">
|
||||
<img src="https://flatlogic.com/assets/icons/footer_logo-102b5debccc6a5a944601a0bc451c7b8da6e282147b7906a42818dda605383ff.svg" alt="Flatlogic" style="height: 24px;">
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="https://flatlogic.com/">
|
||||
<img src="https://flatlogic.com/assets/icons/footer_logo-102b5debccc6a5a944601a0bc451c7b8da6e282147b7906a42818dda605383ff.svg" alt="Flatlogic" width="120">
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.php">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="surveys.php">Surveys</a>
|
||||
</li>
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.php">Home</a>
|
||||
<a class="nav-link" href="dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="admin.php">Admin</a>
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="register.php">Register</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
</div>
|
||||
</nav>
|
||||
Loading…
x
Reference in New Issue
Block a user