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>';

Share this post

Link to post
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.

Share this post

Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Peter Knight
      I have a few web forms which require testing on a weekly basis and I don't want the recipients (administrators) to receive these test emails.
      What would be a good way to test approx 15 forms from the front end and have the test delivered a list of secondary administrator recipients?
      I'm thinking that I could have some kind of config file which watches for a trigger word or email and then understands that it's a test and to bypass the normal admins?
      All of the forms ask for an email address so I could setup an email such as 'testform@email.not' etc which my config file (hook?) would watch for.
      Or is there a better way to do this?
      Additionally, I have a few extra requirements...
      Forms should goto an alternative success page. This is because I don't want my test to skew my Google Analytics conversion tracking Forms would need to be tested from the front-end and not the PW admin area Any advice appreciated.
      BTW I realise this should be posted in the proper FormBuilder support forum. I am in the process of renewing my license for access to that support forum.
    • By DooM
      Hey guys,
      I'm using Form builder module by Ryan and I'm trying to render HTML success message after form is sent using value from this field:

      but it renders exactly as it is written in the field, not as HTML. To render it I just use echo
      <?= $successMessage ?> What am I missing?
      Thanks for any help. 🧒
    • By jds43
      Hello, I have a Page Reference by template radio button field to promote a certain page (only two options), but I'd like to target the page that isn't selected. This would be used dynamically throughout the site.
      Does anyone know how I could accomplish this? Would I use something like remove() or not()?
    • By J_Szwarga
      What is the best practice for having a form (only accessible to a logged in user) save the user's progress between sections of the form? Fieldsets? Multiple forms?
      Use case: I have a very long application form that would take 30 minutes for the applicant to fill out and I would hate for all progress to be lost due to user error. The progress needs to be logged into the user's page.
    • By Marcel
      - we made a page as admins
      - as admins each  <img> tag is loaded and images are displayed
      - we tested the page as a pre-definded test user which is "guest" (Admin Theme: Reno)
      - as test user each <img> is missing and so no image is displayed
      I checked this in dev-mode on firefox and chrome. Does anyone have an idea or has had similar issues?
      Thank you in advance.
  • Create New...