3
I have a form with some "modules" (module = a set of questions - I do not know if it is the appropriate technical term...), so 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" (divs
hidden, that will arise in place of the previous, as the user advances in the questions).
For example:
- module 1 = 8 pages - 14 questions
- module 2 = 3 pages - 7 questions
- module 3 = 20 pages - 27 questions
- ...
So, thinking for now just amount of pages, and imagining only one page for each module to start the attempt, I did something more or less 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 variables $modulo
are boolean session variables, which indicate whether the module has been chosen previously (in a form
that creates 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 many progress bars (up to 30, depending on how many modules...), I think that this way will be enough to repeat code, bad to read, etc...
So the question is:
How best to create a function to automate a dynamic progress bar?
So I don’t understand @Guilhermenascimento. Do you mean if you update your browser? If it is not, it is without Ajax... or JS... after the user chooses the modules, these variables are saved
$modulo
, and from them I know what percentage should appear, then I started doing it the way up, half in the arm hehe...– gustavox
Variables are temporary instances, once updated the page they disappear, or have the value modified.
– Edilson
@Guilhermenascimento It really is what it seems.
– Edilson
So @Guilhermenascimento and Edilson, I’m using session variables to store the states, so after rendering the page (tbm I’m not sure that’s the term, but I say at the time that PHP takes the HTML templates and assembles the form, I use these variables in the templates to know how many pages... is the same way I use to change the links of the "Continue" buttons to change the Ivs... but I wanted to do it in a simpler way... I don’t know if I could understand, anything of a touch that edits the question... is that I thought it would be too long if I added all ...
– gustavox
necessary code to understand how the entire system works... The variables are like this:
if (isset($_POST['modulo1'])) {
 $modulo1 = $_POST['modulo1'];
 $_SESSION['modulo1'] = $modulo1;
} else {
 $modulo1 = false;
 $_SESSION['modulo1'] = false;
}

@Edilson– gustavox
This violates the principles of dynamization on the page, and there will be no change in real time. Instead of adding an existing percentage, a new one will be added to the total value.
– Edilson
Yes, it is dynamic in that it depends on the number of modules chosen before, but when you assemble the page no matter how many questions or pages have passed, this account "has already been done", when the modules were selected, then PHP will create in the templates with this heap of
if
... @Guillhermenascimento– gustavox
Yes @Edilson, there will be no change in real time, but if the user chooses 2 modules with 10 pages, then it will be 10% per page, and if it is 1 module with 5 pages, it will be 20% per page. I think about doing it in real time in the future, getting the question answered, but I have no idea how to do it, and so it already meets what I need... I do not understand what you mean by "violates the principles of dynamization on the page"... could clarify better? Thanks.
– gustavox
When I have time, if there’s still no solution to the problem, I’ll answer.
– Edilson
So it’s @Edilson and I that are confused because the word Modulos is a little abstract and can mean anything, but it’s pretty clear now yes :)
– Guilherme Nascimento
Ah, nice, thanks a lot! @Guilhermenascimento I even wondered whether this word would cause confusion... and how I use it in the system for users, I think I’ll even re-evaluate its use. + 1
– gustavox
@Gustavox, let me get this straight. If I fall for a module like this, I can only go to module 3 if I’ve completed module 1 and 2, right? So would it be like "a college", passing the grades... or not, one can do module 4 and 7 at the same time, as long as those modules are not each other’s prerequisites? If this is the first case I think I have a complete code in my head...
– Enrique René
That’s not quite it Henry... I think until the title and description of the question are not quite certain even... First has a page with several
checkboxes
where the user chooses which groups of questions he wants to answer. Then from this choice a page is mounted with these groups (can be up to a single group). It’s a single page, but all the questions are in hidden Ivs, and when it answers a the continue button opens, and it advances to the next hidden div... [continues]– gustavox
What happens is that each group has a lot of questions, so depending on the group that is chosen, there will be a certain amount of hidden Ivs, and in each one I put a progress bar... Take a look at the question (I gave a modified one), and see how I am doing without using a function, only with
ifs
... I think that from your answer I am getting a solution here, but I have no time to finish, if I can put here... But if you have an idea for another code I would love to see! : ) Thanks!– gustavox
Just to top it off, this bar is not dynamic in the sense of being modified depending on the questions answered, but only the choice in the initial checkbox. It won’t change anything by answering a question, or by clicking the forward button... So for example, if he chose 2 modules out of a total of 20 questions (hidden Ivs) the bar advance would always be 5% by 5%... if there were ten, it would be 10% by 10%...
– gustavox
Oops, sorry, I stuck a
H
in your name in the first comment... hehe– gustavox