diff --git a/app/Http/Controllers/ResponseController.php b/app/Http/Controllers/ResponseController.php index 8963e14..032ea8c 100644 --- a/app/Http/Controllers/ResponseController.php +++ b/app/Http/Controllers/ResponseController.php @@ -1,7 +1,7 @@ id) + ->orderBy('submitted_at', 'desc') + ->get() + ->groupBy('response_id'); + + return view('responses.viewResponses', compact('form', 'responses')); +} + public function showForm(Form $form) { $questions = $form->questions; @@ -44,12 +55,16 @@ class ResponseController extends Controller public function submitForm(Request $request, Form $form) { + Log::info($request->all()); // Log the entire request data for debugging + // Validate and process form submission $validatedData = $request->validate([ 'answers' => 'required|array', 'answers.*' => 'required', ]); + Log::info($validatedData); // Log the validated data for debugging + // Generate a UUID for response_id $responseId = Uuid::uuid4()->toString(); @@ -67,16 +82,5 @@ class ResponseController extends Controller return redirect()->route('responses.showForm', $form) ->with('success', 'Response submitted successfully.'); -} - // View responses for the form owner - 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'); - - return view('responses.viewResponses', compact('form', 'responses')); } } diff --git a/package-lock.json b/package-lock.json index be4707e..e67502b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "LaraForms-main", + "name": "Forms_Laravel", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/resources/views/responses/showForm.blade.php b/resources/views/responses/showForm.blade.php index 6a69c0d..7ebe7db 100644 --- a/resources/views/responses/showForm.blade.php +++ b/resources/views/responses/showForm.blade.php @@ -72,11 +72,15 @@ @endforeach @elseif($question->type == 'dropdown') - @foreach (json_decode($question->options) as $option) @endforeach + @elseif($question->type == 'short_answer') + + @elseif($question->type == 'long_answer') + @endif @endforeach @@ -87,3 +91,4 @@ @endsection + diff --git a/resources/views/responses/viewResponse.blade.php b/resources/views/responses/viewResponse.blade.php index 9015e92..2b571b3 100644 --- a/resources/views/responses/viewResponse.blade.php +++ b/resources/views/responses/viewResponse.blade.php @@ -81,9 +81,6 @@

Response from {{ $responses->first()->user->name ?? 'Anonymous' }} - {{ $responses->first()->submitted_at }}

- {{-- Debugging output --}} -
{{ print_r($questions) }}
-
{{ print_r($responses) }}
@foreach ($responses as $response) @php @@ -94,23 +91,21 @@ @if ($question)

{{ $question->question_text }}

- @if (in_array($question->type, ['multiple_choice', 'checkbox', 'dropdown'])) - @if ($question->type == 'dropdown') - - @else + @if ($question->type == 'dropdown') + + @endforeach - @endif + + @elseif (in_array($question->type, ['multiple_choice', 'checkbox'])) + @foreach (json_decode($question->options) as $option) +

+ + {{ $option }} +

+ @endforeach @else

{{ is_array($decodedAnswers) ? implode(', ', $decodedAnswers) : $decodedAnswers }}

@endif @@ -126,3 +121,4 @@ +