Jump to content

Multiple form submission and retrieve all data at the end


Recommended Posts

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..... :'(


<?php include("./head.inc"); 


<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" >
            $name = 0;
            $arrlength1 = count($name);      
            echo $arrlength1;          
                    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" />


    </div><!-- body ends -->

    <?php //include("./sidebar.inc"); ?>

  </div><!-- content-border ends --> 
</div><!-- content ends -->

<?php include("./footer.inc"); ?>


$name = $input->post['answer'];

$myarray = array();
array_push($myarray, $name);

$answers =array('one','right');
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)
$url = "question-".$arrlength;

 echo "<h1>you have scored :".$score."</h1>";
 echo '<pre>'; // just to check the user inputs.
 echo '</pre>';
Link to comment
Share on other sites

1. Is "$name" defined in the ./functions.php file? Because in the quiz.php, you don't populate it with anything.

2. in the quiz.php, when you generate the hidden inputs, you output "$name[$x]". You should output "{$name[$x]}" (note the curly braces) to output value of $name at position $x.

That's what I could think of after quick read-through.

Link to comment
Share on other sites


  • Create New...