diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index 7c5028d..ee950cf 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -20,7 +20,7 @@ class FormController extends Controller $publishedForms = Form::where('is_published', true)->count(); $totalResponses = Response::count(); - $forms = Form::where('user_id', Auth::id())->get(); + $forms = Form::where('user_id', Auth::id())->orderBy('created_at', 'desc')->get(); return view('forms.index', [ 'forms' => $forms, 'totalForms' => $totalForms, @@ -54,6 +54,55 @@ class FormController extends Controller } + public function createWithTemplate($template) +{ + $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; + + 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; + + 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; + } + + return view('forms.create', ['data' => $data]); +} + + + public function store(Request $request) { diff --git a/app/Http/Controllers/ResponseController.php b/app/Http/Controllers/ResponseController.php index 94c5fe2..88e154c 100644 --- a/app/Http/Controllers/ResponseController.php +++ b/app/Http/Controllers/ResponseController.php @@ -21,6 +21,12 @@ class ResponseController extends Controller return view('responses.index', compact('form', 'responses')); } + public function showSuccess(Form $form) +{ + return view('responses.success', compact('form')); +} + + // Display a specific response public function viewResponse(Form $form, $responseId) { diff --git a/public/images/add.png b/public/images/add.png index 3d0b46f..8b5f3cd 100644 Binary files a/public/images/add.png and b/public/images/add.png differ diff --git a/public/images/bin.png b/public/images/bin.png index 81e7c49..1a51853 100644 Binary files a/public/images/bin.png and b/public/images/bin.png differ diff --git a/resources/views/forms/create.blade.php b/resources/views/forms/create.blade.php index bbee8e6..716bc8a 100644 --- a/resources/views/forms/create.blade.php +++ b/resources/views/forms/create.blade.php @@ -48,8 +48,8 @@
- - + +
diff --git a/resources/views/forms/edit.blade.php b/resources/views/forms/edit.blade.php index 466f484..088fa96 100644 --- a/resources/views/forms/edit.blade.php +++ b/resources/views/forms/edit.blade.php @@ -11,6 +11,8 @@ + + + + + + +
+ @if (session('success')) + + @endif + @if (session('delete')) + + @endif +
+
+ 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.

+
+
+
+

Recent Forms

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

No forms available.

+ @else + + + + + + + + + + + + + @foreach ($forms as $form) + + + + + + + + + @endforeach + +
Form TitleCreated AtResponsesStatus
+ {{ $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 +
+
+ + + + + + + diff --git a/resources/views/forms/show.blade.php b/resources/views/forms/show.blade.php index 1f49701..2538e60 100644 --- a/resources/views/forms/show.blade.php +++ b/resources/views/forms/show.blade.php @@ -30,7 +30,7 @@     -
+
diff --git a/resources/views/responses/showForm.blade.php b/resources/views/responses/showForm.blade.php index a520a98..d2ba288 100644 --- a/resources/views/responses/showForm.blade.php +++ b/resources/views/responses/showForm.blade.php @@ -1,106 +1,4 @@ {{-- @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') @@ -191,7 +89,120 @@ text: 'Form Submitted Successfully', icon: 'success', confirmButtonText: 'OK' - }); + }).then()=>{ + window.location.href + } + }); + }); + +@endsection --}} + + + + + + + +@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 + + +
+
+
+ + diff --git a/resources/views/responses/success.blade.php b/resources/views/responses/success.blade.php new file mode 100644 index 0000000..5b07ef0 --- /dev/null +++ b/resources/views/responses/success.blade.php @@ -0,0 +1,13 @@ +@extends('layouts.app') + +@section('content') +
+
+

Response Submitted Successfully

+

Thank you for your response.

+ + Fill Another Response + +
+
+@endsection diff --git a/resources/views/responses/viewResponses.blade.php b/resources/views/responses/viewResponses.blade.php index e25b1ad..a8eb0c2 100644 --- a/resources/views/responses/viewResponses.blade.php +++ b/resources/views/responses/viewResponses.blade.php @@ -141,110 +141,6 @@ }, 2000); } - function showTab(tabId) { - document.querySelectorAll('.tab-content').forEach(tab => { - tab.classList.add('hidden'); - }); - document.getElementById(tabId).classList.remove('hidden'); - - document.querySelectorAll('.tab-link').forEach(link => { - link.classList.remove('border-purple-600', 'text-purple-600'); - }); - document.querySelector(`[onclick="showTab('${tabId}')"]`).classList.add('border-purple-600', 'text-purple-600'); - } - - document.addEventListener('DOMContentLoaded', function () { - const statistics = @json($statistics); - console.log(statistics); // Log statistics for debugging - - Object.keys(statistics).forEach(questionId => { - const ctx = document.getElementById(`chart-${questionId}`).getContext('2d'); - const stat = statistics[questionId]; - - let labels = []; - let data = []; - let backgroundColors = []; - - if (stat.type === 'multiple_choice' || stat.type === 'checkbox' || stat.type === 'dropdown') { - const optionCounts = {}; - stat.responses.forEach(response => { - if (Array.isArray(response)) { - response.forEach(option => { - if (option in optionCounts) { - optionCounts[option]++; - } else { - optionCounts[option] = 1; - } - }); - } else { - if (response in optionCounts) { - optionCounts[response]++; - } else { - optionCounts[response] = 1; - } - } - }); - - labels = Object.keys(optionCounts); - data = Object.values(optionCounts); - backgroundColors = labels.map((_, index) => `rgba(${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, 0.5)`); - } - - if (stat.type === 'multiple_choice' || stat.type === 'dropdown') { - new Chart(ctx, { - type: 'pie', - data: { - labels: labels, - datasets: [{ - label: 'Responses', - data: data, - backgroundColor: backgroundColors, - borderColor: backgroundColors.map(color => color.replace('0.5', '1')), - borderWidth: 1 - }] - }, - options: { - scales: { - y: { - beginAtZero: true - } - } - responsive: true, - plugins: { - legend: { - position: 'top', - }, - tooltip: { - enabled: true - } - } - } - }); - } else if (stat.type === 'checkbox') { - new Chart(ctx, { - type: 'bar', - data: { - labels: labels, - datasets: [{ - label: 'Responses', - data: data, - backgroundColor: backgroundColors, - borderColor: backgroundColors.map(color => color.replace('0.5', '1')), - borderWidth: 1 - }] - }, - options: { - scales: { - y: { - beginAtZero: true - } - } - } - }); - } - }); - }); - diff --git a/routes/web.php b/routes/web.php index 2aedfd6..12e591e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -23,6 +23,8 @@ Route::middleware(['auth'])->group(function () { Route::delete('/forms/{form}', [FormController::class, 'destroy'])->name('forms.destroy'); Route::get('/forms/{form}/preview', [FormController::class, 'preview'])->name('forms.preview'); Route::patch('/forms/{form}/publish', [FormController::class, 'togglePublish'])->name('forms.publish'); + Route::get('/forms/template/{template}', [FormController::class, 'createWithTemplate'])->name('forms.template'); + }); // Response routes @@ -30,5 +32,6 @@ Route::middleware(['auth'])->group(function () { Route::get('/forms/respond/{form}', [ResponseController::class, 'showForm'])->name('responses.showForm'); Route::post('/forms/respond/{form}', [ResponseController::class, 'submitForm'])->name('responses.submitForm'); Route::get('/forms/{form}/responses', [ResponseController::class, 'viewResponses'])->name('responses.viewResponses'); + Route::get('/forms/{form}/success', [ResponseController::class, 'showSuccess'])->name('responses.success'); Route::get('/forms/{form}/responses/{responseId}', [ResponseController::class, 'viewResponse'])->name('responses.viewResponse'); });