I have a form with some "modules" (module = a set of questions - I do not know if it is the appropriate technical term ...), so that, depending on which module is chosen, a certain amount of questions will be inserted in the form to be answered.
And depending on how many modules have been included, the form will have a certain amount of "pages" (% hidden, which will appear instead of the previous one, as the user advances the questions).
For example:
- module 1 = 8 pages - 14 questions
- module 2 = 3 pages - 7 questions
- module 3 = 20 pages - 27 questions
- ...
So, just thinking of just a few pages, and imagining only one page for each module to begin the attempt, I did something like this:
<div class="col-md-10">
<?php
if (!$modulo1 && !$modulo2 && $modulo3) {
echo " <div class='progress'>
<div class='progress-bar progress-bar-info' role='progressbar' style='width:30%'> 30%
</div>
</div>";
}
elseif (!$modulo1 && $modulo2 && $modulo3) {
echo " <div class='progress'>
<div class='progress-bar progress-bar-info' role='progressbar' style='width:20%'> 20%
</div>
</div>
";
}
elseif ($modulo1 && $modulo2 && $modulo3) {
echo " <div class='progress'>
<div class='progress-bar progress-bar-info' role='progressbar' style='width:10%'> 10%
</div>
</div>
";
}
?>
</div>
The divs
variables are Boolean session variables, which tell you if the module was previously chosen (in $modulo
creating the question form, where the user chose which modules ...):
if (isset($_POST['modulo1'])) {
$modulo1 = $_POST['modulo1'];
$_SESSION['modulo1'] = $modulo1;
} else {
$modulo1 = false;
$_SESSION['modulo1'] = false;
}
But as there are a lot of progress bars (up to 30, depending on how many modules ...), I think this way it will be enough with repeated code, bad reading, etc ...
So the question is:
What is the best way to create a function to automate a dynamic progress bar?