From 0d8c522732173ba46afdeed1a801a982ba887926 Mon Sep 17 00:00:00 2001 From: yash Date: Wed, 24 Jul 2024 11:11:55 +0530 Subject: [PATCH] Code and bug fixes --- app/Http/Controllers/FormController.php | 142 +++-- app/Http/Controllers/HomeController.php | 12 +- app/Http/Controllers/QuestionController.php | 12 +- app/Http/Controllers/ResponseController.php | 194 ++++--- public/js/script.js | 161 +++--- public/js/statistics.js | 129 ----- resources/views/forms/create.blade.php | 4 +- resources/views/forms/edit.blade.php | 534 ++++++++++-------- resources/views/forms/index.blade.php | 205 +------ resources/views/responses/index.blade.php | 39 -- resources/views/responses/showForm.blade.php | 105 ---- .../views/responses/viewResponse.blade.php | 2 +- 12 files changed, 585 insertions(+), 954 deletions(-) delete mode 100644 public/js/statistics.js diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index ee950cf..1e8a20e 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -55,94 +55,92 @@ class FormController extends Controller public function createWithTemplate($template) -{ - $data = []; + { + $data = []; - switch ($template) { - case 'contact': - $data = [ - 'title' => 'Contact Information', - 'description' => 'Template for collecting contact information.', - 'questions' => [ - ['type' => 'text', 'question_text' => 'Name'], - ['type' => 'text', 'question_text' => 'Email'], - // Add more questions as needed - ], - ]; - break; + switch ($template) { + case 'contact': + $data = [ + 'title' => 'Contact Information', + 'description' => 'Template for collecting contact information.', + 'questions' => [ + ['type' => 'text', 'question_text' => 'Name'], + ['type' => 'text', 'question_text' => 'Email'], + // Add more questions as needed + ], + ]; + break; - case 'rsvp': - $data = [ - 'title' => 'RSVP', - 'description' => 'Event Address: 123 Your Street Your City, ST 12345 + case 'rsvp': + $data = [ + 'title' => 'RSVP', + 'description' => 'Event Address: 123 Your Street Your City, ST 12345 Contact us at (123) 456-7890 or no_reply@example.com ', - 'questions' => [ - ['type' => 'text', 'question_text' => 'Can you attend?'], - ['type' => 'text', 'question_text' => 'Number of Guests'], - // Add more questions as needed - ], - ]; - break; + 'questions' => [ + ['type' => 'text', 'question_text' => 'Can you attend?'], + ['type' => 'text', 'question_text' => 'Number of Guests'], + ], + ]; + break; - case 'party': - $data = [ - 'title' => 'Party Invite', - 'description' => 'Template for party invitations.', - 'questions' => [ - ['type' => 'text', 'question_text' => 'Name'], - ['type' => 'text', 'question_text' => 'RSVP Status'], - // Add more questions as needed - ], - ]; - break; + case 'party': + $data = [ + 'title' => 'Party Invite', + 'description' => 'Template for party invitations.', + 'questions' => [ + ['type' => 'text', 'question_text' => 'Name'], + ['type' => 'text', 'question_text' => 'RSVP Status'], + ], + ]; + break; + } + + return view('forms.create', ['data' => $data]); } - return view('forms.create', ['data' => $data]); -} - public function store(Request $request) -{ - try { - $validatedData = $request->validate([ - 'title' => 'required|string|max:255', - 'description' => 'nullable|string', - 'questions' => 'required|array', - 'questions.*.type' => 'required|string|in:multiple_choice,checkbox,dropdown,text', - 'questions.*.text' => 'required|string', - 'questions.*.options' => 'nullable|array', - 'questions.*.required' => 'nullable|boolean', - ]); + { + try { + $validatedData = $request->validate([ + 'title' => 'required|string|max:255', + 'description' => 'nullable|string', + 'questions' => 'required|array', + 'questions.*.type' => 'required|string|in:multiple_choice,checkbox,dropdown,text', + 'questions.*.text' => 'required|string', + 'questions.*.options' => 'nullable|array', + 'questions.*.required' => 'nullable|boolean', + ]); - $form = new Form(); - $form->title = $validatedData['title']; - $form->description = $validatedData['description']; - $form->is_published = $request->input('is_published', false); - $form->user_id = Auth::id(); - $form->save(); + $form = new Form(); + $form->title = $validatedData['title']; + $form->description = $validatedData['description']; + $form->is_published = $request->input('is_published', false); + $form->user_id = Auth::id(); + $form->save(); - foreach ($validatedData['questions'] as $questionData) { - $question = new Question(); - $question->form_id = $form->id; - $question->type = $questionData['type']; - $question->question_text = $questionData['text']; - $question->options = isset($questionData['options']) ? json_encode($questionData['options']) : null; - $question->required = isset($questionData['required']) ? $questionData['required'] : false; - $question->save(); + foreach ($validatedData['questions'] as $questionData) { + $question = new Question(); + $question->form_id = $form->id; + $question->type = $questionData['type']; + $question->question_text = $questionData['text']; + $question->options = isset($questionData['options']) ? json_encode($questionData['options']) : null; + $question->required = isset($questionData['required']) ? $questionData['required'] : false; + $question->save(); + } + + + + return response()->json(['success' => true, 'form_id' => $form->id]); + } catch (\Exception $e) { + Log::error('Error saving form: ' . $e->getMessage(), ['exception' => $e]); + return response()->json(['success' => false, 'message' => 'Error saving form'], 500); } - - - - return response()->json(['success' => true, 'form_id' => $form->id]); - } catch (\Exception $e) { - Log::error('Error saving form: ' . $e->getMessage(), ['exception' => $e]); - return response()->json(['success' => false, 'message' => 'Error saving form'], 500); } -} public function show(Form $form) { diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 9d8220c..fc53a17 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -6,21 +6,13 @@ use Illuminate\Http\Request; class HomeController extends Controller { - /** - * Create a new controller instance. - * - * @return void - */ + public function __construct() { $this->middleware('auth'); } - /** - * Show the application dashboard. - * - * @return \Illuminate\Contracts\Support\Renderable - */ + public function index() { return view('forms.index'); diff --git a/app/Http/Controllers/QuestionController.php b/app/Http/Controllers/QuestionController.php index 5328feb..ce29f7e 100644 --- a/app/Http/Controllers/QuestionController.php +++ b/app/Http/Controllers/QuestionController.php @@ -17,14 +17,14 @@ class QuestionController extends Controller public function store(Form $form, Request $request) { - // Validate question data + $validatedData = $request->validate([ 'type' => 'required|string|in:multiple_choice,checkbox,dropdown,short_answer,long_answer', 'question_text' => 'required|string', - 'options' => 'nullable|array', // If needed based on question type + 'options' => 'nullable|array', ]); - // Create new question for the form + $question = new Question(); $question->form_id = $form->id; $question->type = $validatedData['type']; @@ -42,14 +42,14 @@ class QuestionController extends Controller public function update(Form $form, Question $question, Request $request) { - // Validate updated question data + $validatedData = $request->validate([ 'type' => 'required|string|in:multiple_choice,checkbox,dropdown,short_answer,long_answer', 'question_text' => 'required|string', - 'options' => 'nullable|array', // If needed based on question type + 'options' => 'nullable|array', ]); - // Update question details + $question->type = $validatedData['type']; $question->question_text = $validatedData['question_text']; $question->options = $validatedData['options'] ?? null; diff --git a/app/Http/Controllers/ResponseController.php b/app/Http/Controllers/ResponseController.php index 88e154c..60b1a59 100644 --- a/app/Http/Controllers/ResponseController.php +++ b/app/Http/Controllers/ResponseController.php @@ -1,6 +1,7 @@ where('form_id', $form->id) - ->get(); - - // Get all questions for the form - $questions = Question::where('form_id', $form->id)->get()->keyBy('id'); - - // Aggregate data for statistics - $statistics = []; - foreach ($questions as $question) { - $statistics[$question->id] = [ - 'question_text' => $question->question_text, - 'type' => $question->type, - 'options' => json_decode($question->options), - 'responses' => [] - ]; - - foreach ($responses as $response) { - $decodedAnswers = json_decode($response->answers, true); - if (isset($decodedAnswers[$question->id])) { - $statistics[$question->id]['responses'][] = $decodedAnswers[$question->id]; - } - } + { + return view('responses.success', compact('form')); } - return view('responses.viewResponse', compact('form', 'responses', 'questions', 'statistics')); -} -public function viewResponses(Form $form) -{ - // Get all responses for the form, grouped by response_id - $responses = Response::where('form_id', $form->id) - ->orderBy('submitted_at', 'desc') - ->get() - ->groupBy('response_id'); + public function viewResponse(Form $form, $responseId) + { - // Get all questions for the form - $questions = Question::where('form_id', $form->id)->get()->keyBy('id'); + $responses = Response::where('response_id', $responseId) + ->where('form_id', $form->id) + ->get(); - // Aggregate data for statistics - $statistics = []; - foreach ($questions as $question) { - $statistics[$question->id] = [ - 'question_text' => $question->question_text, - 'type' => $question->type, - 'options' => json_decode($question->options, true), - 'responses' => [], - ]; - foreach ($responses as $responseGroup) { - foreach ($responseGroup as $response) { + $questions = Question::where('form_id', $form->id)->get()->keyBy('id'); + + + $statistics = []; + foreach ($questions as $question) { + $statistics[$question->id] = [ + 'question_text' => $question->question_text, + 'type' => $question->type, + 'options' => json_decode($question->options), + 'responses' => [] + ]; + + foreach ($responses as $response) { $decodedAnswers = json_decode($response->answers, true); if (isset($decodedAnswers[$question->id])) { $statistics[$question->id]['responses'][] = $decodedAnswers[$question->id]; } } } + + return view('responses.viewResponse', compact('form', 'responses', 'questions', 'statistics')); } - return view('responses.viewResponses', compact('form', 'responses', 'statistics', 'questions')); -} + + public function viewResponses(Form $form) + { + + $responses = Response::where('form_id', $form->id) + ->orderBy('submitted_at', 'desc') + ->get() + ->groupBy('response_id'); + + + $questions = Question::where('form_id', $form->id)->get()->keyBy('id'); + + + $statistics = []; + foreach ($questions as $question) { + $statistics[$question->id] = [ + 'question_text' => $question->question_text, + 'type' => $question->type, + 'options' => json_decode($question->options, true), + 'responses' => [], + ]; + + foreach ($responses as $responseGroup) { + foreach ($responseGroup as $response) { + $decodedAnswers = json_decode($response->answers, true); + if (isset($decodedAnswers[$question->id])) { + $statistics[$question->id]['responses'][] = $decodedAnswers[$question->id]; + } + } + } + } + + return view('responses.viewResponses', compact('form', 'responses', 'statistics', 'questions')); + } public function showForm(Form $form) @@ -106,53 +107,48 @@ public function viewResponses(Form $form) } public function submitForm(Request $request, Form $form) -{ - Log::info($request->all()); // Log the entire request data for debugging + { + Log::info($request->all()); - // Fetch all questions for the form - $questions = $form->questions; - // Extract IDs of required questions - $requiredQuestionIds = $questions->where('required', true)->pluck('id')->toArray(); + $questions = $form->questions; - // Validate and process form submission - $validatedData = $request->validate([ - 'answers' => 'required|array', - 'answers.*' => 'required', // Ensure all answers are provided - ]); - // Ensure all required questions are answered - foreach ($requiredQuestionIds as $requiredQuestionId) { - if (!array_key_exists($requiredQuestionId, $validatedData['answers'])) { - return redirect()->back() - ->withErrors(['errors' => 'Please answer all required questions.']) - ->withInput(); + $requiredQuestionIds = $questions->where('required', true)->pluck('id')->toArray(); + + + $validatedData = $request->validate([ + 'answers' => 'required|array', + 'answers.*' => 'required', + ]); + + + foreach ($requiredQuestionIds as $requiredQuestionId) { + if (!array_key_exists($requiredQuestionId, $validatedData['answers'])) { + return redirect()->back() + ->withErrors(['errors' => 'Please answer all required questions.']) + ->withInput(); + } } + + Log::info($validatedData); + + + $responseId = Uuid::uuid4()->toString(); + + + foreach ($validatedData['answers'] as $questionId => $answer) { + $response = new Response(); + $response->response_id = $responseId; + $response->question_id = $questionId; + $response->form_id = $form->id; + $response->user_id = auth()->id(); + $response->answers = json_encode($answer); + $response->submitted_at = now(); + $response->save(); + } + + return redirect()->route('responses.showForm', $form) + ->with('success', 'Response submitted successfully.'); } - - Log::info($validatedData); // Log the validated data for debugging - - // Generate a UUID for response_id - $responseId = Uuid::uuid4()->toString(); - - // Save each question's response - foreach ($validatedData['answers'] as $questionId => $answer) { - $response = new Response(); - $response->response_id = $responseId; // Assign the generated UUID - $response->question_id = $questionId; - $response->form_id = $form->id; - $response->user_id = auth()->id(); - $response->answers = json_encode($answer); - $response->submitted_at = now(); - $response->save(); - } - - return redirect()->route('responses.showForm', $form) - ->with('success', 'Response submitted successfully.'); -} - - - - - } diff --git a/public/js/script.js b/public/js/script.js index 57b8ce2..80820f8 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -21,25 +21,31 @@ document.addEventListener("DOMContentLoaded", function () { } function changeQuestionType(selectElement) { - const questionContainer = selectElement.closest('.question'); - const optionsContainer = questionContainer.querySelector('.options-container'); - const addOptionButton = questionContainer.querySelector('.btn-secondary'); + const questionContainer = selectElement.closest(".question"); + const optionsContainer = + questionContainer.querySelector(".options-container"); + const addOptionButton = + questionContainer.querySelector(".btn-secondary"); const questionType = selectElement.value; // Clear the options container - optionsContainer.innerHTML = ''; + optionsContainer.innerHTML = ""; - if (questionType === 'multiple_choice' || questionType === 'checkbox' || questionType === 'dropdown') { - const optionDiv = document.createElement('div'); - optionDiv.className = 'option d-flex align-items-center mb-2'; + if ( + questionType === "multiple_choice" || + questionType === "checkbox" || + questionType === "dropdown" + ) { + const optionDiv = document.createElement("div"); + optionDiv.className = "option d-flex align-items-center mb-2"; optionDiv.innerHTML = ` `; optionsContainer.appendChild(optionDiv); - addOptionButton.style.display = 'inline-block'; // Show the "Add Option" button - } else if (questionType === 'text') { - addOptionButton.style.display = 'none'; // Hide the "Add Option" button + addOptionButton.style.display = "inline-block"; // Show the "Add Option" button + } else if (questionType === "text") { + addOptionButton.style.display = "none"; // Hide the "Add Option" button } } @@ -88,34 +94,37 @@ document.addEventListener("DOMContentLoaded", function () { function updateAddButtonPosition() { const questions = questionsSection.querySelectorAll(".question"); - const sidebar = document.getElementById("moveableDiv"); + const sidebar = document.getElementById("moveableDiv"); - if (questions.length > 0) { - const lastQuestion = questions[questions.length - 1]; - const offsetTop = lastQuestion.offsetTop; - const sidebarHeight = sidebar.offsetHeight; - const containerHeight = questionsSection.offsetHeight; + if (questions.length > 0) { + const lastQuestion = questions[questions.length - 1]; + const offsetTop = lastQuestion.offsetTop; + const sidebarHeight = sidebar.offsetHeight; + const containerHeight = questionsSection.offsetHeight; - // Calculate the position of the last question relative to the top of the container - const newPosition = offsetTop + lastQuestion.offsetHeight; + // Calculate the position of the last question relative to the top of the container + const newPosition = offsetTop + lastQuestion.offsetHeight; - // Ensure the sidebar stays within the bounds of the container - if (newPosition + sidebarHeight <= containerHeight) { - sidebar.style.transform = `translateY(${newPosition}px)`; - console.log(`Moving sidebar to: ${newPosition}px`); + // Ensure the sidebar stays within the bounds of the container + if (newPosition + sidebarHeight <= containerHeight) { + sidebar.style.transform = `translateY(${newPosition}px)`; + console.log(`Moving sidebar to: ${newPosition}px`); + } else { + sidebar.style.transform = `translateY(${ + containerHeight - sidebarHeight + }px)`; + console.log(`Moving sidebar to bottom of container`); + } } else { - sidebar.style.transform = `translateY(${containerHeight - sidebarHeight}px)`; - console.log(`Moving sidebar to bottom of container`); + sidebar.style.transform = `translateY(0px)`; + console.log("No questions, moving sidebar to top"); } - } else { - sidebar.style.transform = `translateY(0px)`; - console.log("No questions, moving sidebar to top"); - } } function saveForm() { const formTitle = document.getElementById("form-title").value; - const formDescription = document.getElementById("form-description").value; + const formDescription = + document.getElementById("form-description").value; const questions = document.querySelectorAll(".question"); let formData = []; @@ -123,26 +132,34 @@ document.addEventListener("DOMContentLoaded", function () { questions.forEach((question) => { const questionType = question.querySelector("select").value; - const questionText = question.querySelector(".question-input").value; - const isRequired = question.querySelector(".required-checkbox").checked; + const questionText = + question.querySelector(".question-input").value; + const isRequired = + question.querySelector(".required-checkbox").checked; let options = []; - if (questionType === 'multiple_choice' || questionType === 'checkbox' || questionType === 'dropdown') { - options = Array.from(question.querySelectorAll(".option-input")).map((input) => input.value); + if ( + questionType === "multiple_choice" || + questionType === "checkbox" || + questionType === "dropdown" + ) { + options = Array.from( + question.querySelectorAll(".option-input") + ).map((input) => input.value); } formData.push({ type: questionType, text: questionText, options: options, - required: isRequired + required: isRequired, }); console.log({ type: questionType, text: questionText, options: options, - required: isRequired + required: isRequired, }); }); @@ -158,56 +175,47 @@ document.addEventListener("DOMContentLoaded", function () { const data = { title: formTitle, description: formDescription, - questions: formData + questions: formData, }; console.log(data); - fetch("/forms", { method: "POST", headers: { "Content-Type": "application/json", - "X-CSRF-TOKEN": csrfToken + "X-CSRF-TOKEN": csrfToken, }, body: JSON.stringify(data), }) - .then((response) => response.json()) - .then((result) => { - if (result.success) { - Swal.fire({ - title: 'Success!', - text: 'Form saved successfully.', - icon: 'success', - confirmButtonText: 'OK' - }).then((result) => { - if (result.isConfirmed) { - window.location.href = "/forms"; - } - }); - } else { - Swal.fire({ - title: 'Error!', - text: 'Failed to save form.', - icon: 'error', - confirmButtonText: 'OK' - }); - } - }) - .catch((error) => { - console.error("Error saving form:", error); - alert("An error occurred while saving the form."); - }); + .then((response) => response.json()) + .then((result) => { + if (result.success) { + Swal.fire({ + title: "Success!", + text: "Form saved successfully.", + icon: "success", + confirmButtonText: "OK", + }).then((result) => { + if (result.isConfirmed) { + window.location.href = "/forms"; + } + }); + } else { + Swal.fire({ + title: "Error!", + text: "Failed to save form.", + icon: "error", + confirmButtonText: "OK", + }); + } + }) + .catch((error) => { + console.error("Error saving form:", error); + alert("An error occurred while saving the form."); + }); } - - - - - - - - window.addNewQuestion = addNewQuestion; window.deleteQuestion = deleteQuestion; window.addOption = addOption; @@ -217,7 +225,10 @@ document.addEventListener("DOMContentLoaded", function () { // document.getElementById("add-question-button").addEventListener("click", addNewQuestion); - document.getElementById("questions_section").addEventListener("DOMNodeInserted", updateAddButtonPosition); - document.getElementById("questions_section").addEventListener("DOMNodeRemoved", updateAddButtonPosition); + document + .getElementById("questions_section") + .addEventListener("DOMNodeInserted", updateAddButtonPosition); + document + .getElementById("questions_section") + .addEventListener("DOMNodeRemoved", updateAddButtonPosition); }); - diff --git a/public/js/statistics.js b/public/js/statistics.js deleted file mode 100644 index 901b9b5..0000000 --- a/public/js/statistics.js +++ /dev/null @@ -1,129 +0,0 @@ -// statistics.js - -// Function to fetch responses from backend -function fetchResponses() { - return fetch('/api/responses') // Replace with your actual API endpoint - .then(response => response.json()) - .catch(error => console.error('Error fetching responses:', error)); -} - -// Function to process fetched responses data -function processDataForCharts(responses, questions) { - const pieData = {}; - const barData = {}; - - responses.forEach(response => { - const question = questions[response.question_id]; - const decodedAnswers = JSON.parse(response.answers); - - // Process data for pie chart - if (!pieData[question.question_text]) { - pieData[question.question_text] = {}; - } - if (question.type === 'multiple_choice' || question.type === 'checkbox') { - JSON.parse(question.options).forEach(option => { - pieData[question.question_text][option] = (pieData[question.question_text][option] || 0) + - (decodedAnswers.includes(option) ? 1 : 0); - }); - } - - // Process data for bar graph (assuming numerical responses) - if (question.type === 'short_answer' || question.type === 'long_answer') { - if (!barData[question.question_text]) { - barData[question.question_text] = { total: 0, count: 0 }; - } - barData[question.question_text].total += parseFloat(response.answers); - barData[question.question_text].count++; - } - }); - - // Calculate averages for bar graph - Object.keys(barData).forEach(key => { - barData[key].average = barData[key].total / barData[key].count; - }); - - return { pieData, barData }; -} - -// Function to render charts using Chart.js -function renderCharts(pieData, barData) { - // Render Pie Chart - const pieChartCanvas = document.getElementById('pieChart'); - new Chart(pieChartCanvas.getContext('2d'), { - type: 'pie', - data: { - labels: Object.keys(pieData), - datasets: Object.keys(pieData).map(question => ({ - label: question, - data: Object.values(pieData[question]), - backgroundColor: getRandomColors(Object.values(pieData[question]).length), - })), - }, - options: { - responsive: true, - plugins: { - legend: { - position: 'top', - }, - tooltip: { - callbacks: { - label: function(context) { - let label = context.label || ''; - if (context.parsed.y !== null) { - label += ': ' + context.parsed.y; - } - return label; - }, - }, - }, - }, - }, - }); - - // Render Bar Graph - const barGraphCanvas = document.getElementById('barGraph'); - new Chart(barGraphCanvas.getContext('2d'), { - type: 'bar', - data: { - labels: Object.keys(barData), - datasets: [{ - label: 'Average Response', - data: Object.values(barData).map(item => item.average.toFixed(2)), - backgroundColor: getRandomColors(Object.keys(barData).length), - }], - }, - options: { - responsive: true, - scales: { - y: { - beginAtZero: true, - }, - }, - }, - }); -} - -// Function to generate random colors -function getRandomColors(count) { - const colors = []; - for (let i = 0; i < count; i++) { - colors.push(`rgba(${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, 0.2)`); - } - return colors; -} - -// Main function to fetch data and render charts -async function main() { - try { - const responses = await fetchResponses(); - const questions = {!! json_encode($questions) !!}; // This assumes $questions is passed to the Blade view from Laravel - - const { pieData, barData } = processDataForCharts(responses, questions); - renderCharts(pieData, barData); - } catch (error) { - console.error('Error processing or rendering charts:', error); - } -} - -// Run main function on page load -window.addEventListener('DOMContentLoaded', main); diff --git a/resources/views/forms/create.blade.php b/resources/views/forms/create.blade.php index 716bc8a..e35b611 100644 --- a/resources/views/forms/create.blade.php +++ b/resources/views/forms/create.blade.php @@ -47,14 +47,14 @@
-
+
-
+
-
-
- -
-
- @foreach ($questions as $index => $question) -
-
- -
-
- -
-
- required ? 'checked' : '' }}> - -
-
- - @if (is_array($question->options)) - @foreach ($question->options as $optionIndex => $option) -
- - -
- @endforeach - @endif - - -
-
- @endforeach - -
- - -
+ < + div style = "max-width: 700px" + class = "container" > + < + form id = "edit-form" + method = "POST" + action = "{{ route('forms.update', $form) }}" + class = "bg-white p-4 rounded shadow-sm" > + @csrf + @method('PUT') + < + div class = "form-group" > + < + input type = "text" + id = "form-title" + name = "title" + class = "form-control form-control-lg text-black" + placeholder = "Untitled Form" + value = "{{ $form->title }}" / > + < + /div> < + div class = "form-group" > + < + input type = "text" + name = "description" + id = "form-description" + class = "form-control form-control-sm text-black" + placeholder = "Form Description" + value = "{{ $form->description }}" / > + < + /div> < + div id = "questions-section" > + @foreach ($questions as $index => $question) + < + div class = "question mb-4 p-3 border rounded bg-light" + data - index = "{{ $index }}" > + < + div class = "form-group" > + < + select class = "form-control question-type" + id = "question-type-{{ $index }}" + name = "questions[{{ $index }}][type]" > + < + option value = "multiple_choice" + {{ $question->type === 'multiple_choice' ? 'selected' : '' }} > Multiple Choice < /option> < + option value = "checkbox" + {{ $question->type === 'checkbox' ? 'selected' : '' }} > Checkbox < /option> < + option value = "dropdown" + {{ $question->type === 'dropdown' ? 'selected' : '' }} > Dropdown < /option> < + option value = "text" + {{ $question->type === 'text' ? 'selected' : '' }} > Text < /option> < / + select > < + /div> < + div class = "form-group" > + < + input type = "text" + id = "question-text-{{ $index }}" + name = "questions[{{ $index }}][text]" + class = "form-control question-input" + value = "{{ $question->question_text }}" + required > + < + /div> < + div class = "form-group form-check" > + < + input type = "checkbox" + id = "question-required-{{ $index }}" + name = "questions[{{ $index }}][required]" + class = "form-check-input" + {{ $question->required ? 'checked' : '' }} > + < + label + for = "question-required-{{ $index }}" + class = "form-check-label" > Required < /label> < / + div > < + div class = "form-group options-container" + style = "{{ $question->type === 'text' ? 'display:none;' : '' }}" > + < + label > Options < /label> + @if (is_array($question->options)) + @foreach ($question->options as $optionIndex => $option) + < + div class = "option d-flex align-items-center mb-2" > + < + input type = "text" + name = "questions[{{ $index }}][options][{{ $optionIndex }}]" + class = "form-control option-input" + value = "{{ $option }}" > + < + span class = "delete-option ml-2 text-danger" + onclick = "deleteOption(this)" + style = "cursor: pointer;" > & #10005; +
+ @endforeach + @endif + - -
-
- - @if (session('success')) - - @endif - @if (session('delete')) - - @endif -
- -

Recent Forms

-
-
- @if ($forms->isEmpty()) -

No forms available.

- @else - - - - - - - - - - - - - @foreach ($forms as $form) - - - - - - - - - @endforeach - -
- Form Title - Created At - Responses - Status -
- {{ $form->title }} -

{{ $form->description }}

-
{{ $form->created_at->format('M d, Y') }} - - View Responses - - @if ($form->is_published) - Published - @else - Unpublished - @endif - - @if (!$form->is_published) - Edit - @else - Edit - @endif - - -
- @csrf - @method('DELETE') - -
-
- @endif -
-
- - - - - - - - - - --}} - - - - - + @@ -230,21 +58,24 @@ class="inline-block px-6 py-3 text-white font-semibold rounded-md shadow bg-purple-700 hover:bg-purple-900 transition duration-200">Start a new form - -
Contact Information
-

Use this template to create a contact information form.

-
- -
RSVP
-

Use this template to create an RSVP form for events.

-
- -
Party Invite
-

Use this template to create a party invite form.

-
+ + +
Total Forms Created
+

{{ $totalForms }}

+
+ + +
Total Forms Published
+

{{ $publishedForms }}

+
+ + +
Total Responses Received
+

{{ $totalResponses }}

+
-
+
+

Recent Forms


diff --git a/resources/views/responses/index.blade.php b/resources/views/responses/index.blade.php index 1250858..962781f 100644 --- a/resources/views/responses/index.blade.php +++ b/resources/views/responses/index.blade.php @@ -1,42 +1,3 @@ -{{-- - - - - - - - - - Responses - - - -
-
- -

{{ $form->title }} - Responses

-
-
-
-
- @if ($responses->isEmpty()) -

No responses available.

- @else - - @endif -
-
- - - --}} - - diff --git a/resources/views/responses/showForm.blade.php b/resources/views/responses/showForm.blade.php index d2ba288..c15b0dc 100644 --- a/resources/views/responses/showForm.blade.php +++ b/resources/views/responses/showForm.blade.php @@ -1,108 +1,3 @@ -{{-- @extends('layouts.app') - - - -@section('content') -
-
-

{{ $form->title }}

-

{{ $form->description }}

- -
- @csrf - @foreach ($questions as $question) -
- - @if ($question->type == 'multiple_choice') - @foreach (json_decode($question->options) as $option) - - @endforeach - @elseif($question->type == 'checkbox') - @foreach (json_decode($question->options) as $option) - - @endforeach - @elseif($question->type == 'dropdown') - - @elseif($question->type == 'text') - - @endif -
- @endforeach - - -
-
-
- - -@endsection --}} - - - - - - - @extends('layouts.app') diff --git a/resources/views/responses/viewResponse.blade.php b/resources/views/responses/viewResponse.blade.php index 3ecda6b..caf5fe0 100644 --- a/resources/views/responses/viewResponse.blade.php +++ b/resources/views/responses/viewResponse.blade.php @@ -18,7 +18,7 @@ Google Form Icon -

{{ $form->title }} - Response Detail

+

{{ $form->title }} - Response Detail