Hey there,
so, basically, I have been reading a few tutorials about making a quiz with PHP, so I decided to write my own quiz, but I am stuck at the answer validation action because I do not know how to properly do so (I am a bit new to PHP, too), so I decided to ask about this.
I haven't got a mysql db yet, that noted, and I want the whole quiz to be displayed within an iframe html tag on another site of mine which does not support PHP hosting itself.
Code:
<?php // quiz.php
header("Content-Type: text/html; charset=utf-8");
?>
<!-- exclude basic html skeleton -->
<form action="validate.php" method="post">
Question 1:
Question Text
<input type="radio" value="0">Answer 1 (false, as value="0" indicates)<br>
<!-- repeat two more times -->
<input type="radio" value="1">Answer 4 (this is my correct answer)<br>
<!-- repeat questions until #35 -->
<!-- end quiz.php, close html tags -->
<?php // validate.php
$res = 0;
foreach($_POST as $score){ // get all answers from post array
$res = $res + $score;
}
switch($res){ // do switch statement to avoid endless elseif statements because we have many answers
case 35:
echo "To submit your score, press the button below.<br><form action='http://forum.forumotion.com/posting.forum?' method='post'>
<textarea style='display: none;'>Scored ".$res." out of 35 possible points.</textarea>
<input type='submit'></form>"; exit; break;
case 34: // repeat until reached at 0
echo "..."; exit; break;
}
?>
The forum URL specified within validate.php is fictional, by the way, but my forum host uses /posting.forum? for its post action.
Thing is, I don't want to specify the value of the answers with HTML because about everyone could inspect the HTML code of the iframe and get every answer correct...
I want to prevent that, of course.
Anyone help?