PHP: Reveal result later after answer?
Hey,
I have the following html and php code.
<form action="Subtraktion (1).php" method="post" target=""> <table> <tr> <td><font face="Roboto Slab" size=+1>Anzahl der Aufgaben eingeben</font></td> <td><input type="Text" name="z" value="" size="" maxlength=""></input></td> <td align="center"><input type="submit" style="font-family: 'Roboto Slab'" background-color="black" name="y" value="Absenden"></td></tr> </table> <br> </form> <?php if((isset($_POST['z'])) and (is_numeric($_POST['z']))) { $zahl = $_POST['z']; { while($zahl>0) { $a = rand(5, 10); $b = rand(0, 5); $erg = $a - $b; $zahl = $zahl - 1; echo "<table class='Tab'>"; echo "<table border='1'>"; echo "<tr> <td>$a - $b = ?</td> <td><input type=\"Text\" name=\g\" value=\"\">\n</td><td>$a - $b = $erg</td></tr>"; echo "</table>"; } }} ?> </body> </html>
This allows the user to calculate tasks – as many as they initially select. The tasks consist of random numbers. My question now is: how can I write the code (using relatively simple commands) so that the result – in this case: $a – $b = $erg – is only revealed once the user has entered their answer to the task in the text field?
Here is the passage again (also visible above together with the entire code):
echo "<table class='Tab'>"; echo "<table border='1'>"; echo "<tr> <td>$a - $b = ?</td> <td><input type=\"Text\" name=\g\" value=\"\">\n</td><td>$a - $b = $erg</td></tr>"; echo "</table>";
Thank you 🙂
There are several options:
1.) Using JavaScript would give you the most flexibility and allow you to implement any actions you want: the result is checked immediately upon input, there's a button to check the results… But then you could just do everything in JavaScript. Without JavaScript, you can't dynamically change the delivered HTML.
2.) With CSS: Validations, etc., don't work, but with the keyword ":hover" you can change the appearance of elements depending on whether you hover over them. This way you could hide the results until the mouse hovers over them. -A bit like a scratch-off screen.
With CSS you can (recently) do a bit more: https://stackoverflow.com/questions/13630229/can-i-have-an-onclick-effect-in-css
3.) You build a standard form. Once the user has calculated all the values and clicked submit, you receive your results, can review them, and display a page with the results. You can either store the randomly selected numbers/questions in the session variable or return them via form fields. "Hidden" fields or read-only input fields are ideal for this.
I have asked the question in a similar way before.
I just tried to phrase it a little more clearly this time.
Are you not allowed to use JavaScript at all?
That would be much better, easier and shorter.