Is there any specific reason you want to store them in sessions? Why not store them straight to database?
Sep 23, 2019
7
Level 1
Save radio button selection value in session variable
Hello All,
I'm building a multiple page quiz.
When users select options(answer) for a question, it should store it in a session variable. If he needs to change the answer later, he can(and update the session variable accordingly). I have 20 questions and an equal number of pages in total.
How to achieve this to store session value? Or is there any other approach suggested.
PS: I am a noob when it comes to building complex functions. A point in the right direction would be appreciated.
This my code:
question1.blade.php
<body>
<div class="container">
<div class="privew">
<div class="questionsBox">
<div class="questions"><h1>Something</h1></div>
<div class="answerList"><h3>You are only allowed to select one option from the given below question</h3></div>
<div class="questions"><h4>Question 1</h4></div>
<div class="questions"><h3>Section 1</h3></div>
<ul class="answerList">
<li>
<label>
<input type="radio" name="answerGroup" value="0" id="answerGroup_0">Yes</label>
</li>
<li>
<label>
<input type="radio" name="answerGroup" value="1" id="answerGroup_1">Rather yes</label>
</li>
<li>
</ul>
</div>
<div class="questionsBox">
<div class="questions"><h3>Section 2</h3></div>
<ul class="answerList">
<li>
<label>
<input type="radio" name="answerGroup" value="2" id="answerGroup_2">Yes</label>
</li>
<li>
<label>
<input type="radio" name="answerGroup" value="3" id="answerGroup_3">Rather yes</label>
</li>
</ul>
</div>
<div class="questionsRow"><a href="{{ route('ques2') }}" class="button" id="nextquestions">Next</a><span>1 from 20</span><a href="{{ route('ques20') }}" class="button" id="nextquestions">Previous</a></div>
</div>
</div>
<script type="text/javascript">
</script>
</body>
TestsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class TestsController extends Controller
{
public function store(Request $request){
$answers = $request->get('answer[]',0);
dd('answers');
return view('ques1');
}
}
Please or to participate in this conversation.