Hello Experts,
I am trying to make a quiz contest in processwire. This quiz needs to show one question per page. The aim of this quiz is to get more page views. so I created a template, where Quiz questions can be uploaded. After answering one question the user is redirected to the next question or URL on clicking the submit button. I am unable to get the form data. I have the form template and the final page to evaluate the scores. I dont understand where I am going wrong. Here is my code.
Please help me out.....
quiz.php
<?php include("./head.inc");
include("./functions.php");
?>
<div id="content" class="row inside search-page"> <!-- content starts -->
<div class="content-border"> <!-- content-border starts -->
<div id="body" class="large-8 columns" role="content"> <!-- body starts -->
<div class="large-12 columns">
<form id="form1" name="form1" method="post" action="../process-quiz" >
<?php
$name = 0;
$arrlength1 = count($name);
echo $arrlength1;
for($x=0;$x<$arrlength1;$x++)
{
echo "<input type='hidden' name='answer[]' value='$name[$x]' />" ;
}
$p = $page->question;
echo "<h1>Q:<span>{$p}</span></h1>";
if($page->quiz_images !=null)
{
$image = $page->quiz_images->url;
echo "<img src='{$image}'>";
}
foreach($page->quiz_options as $c)
{
echo "<input type='radio' name='answer[]' value=\"{$c->quiz_answer_text}\">{$c->quiz_answer_text}<br/>";
}
?>
<input type="submit" name="button" id="button" value="Next" />
</form>
</div>
</div><!-- body ends -->
<?php //include("./sidebar.inc"); ?>
</div><!-- content-border ends -->
</div><!-- content ends -->
<?php include("./footer.inc"); ?>
process-quiz.php
<?php
$name = $input->post['answer'];
$arrlength=count($name);
$myarray = array();
array_push($myarray, $name);
$answers =array('one','right');
$score=0;
foreach ($myarray as $innerArray) {
// Check type
if (is_array($innerArray)){
// Scan through inner loop
foreach ($innerArray as $value) {
//echo $value."<br />";
foreach($answers as $key)
{
if($value == $key)
{
$score++;
}
}
}
}
}
$url = "question-".$arrlength;
if($arrlength>2)
{
$url="process-quiz.php";
}
$session->redirect("http://www.example.in/temp/quiz-section/$url",false);
echo "<h1>you have scored :".$score."</h1>";
echo '<pre>'; // just to check the user inputs.
print_r($myarray);
echo '</pre>';
}?>