Jump to content


Photo

How to make a form go away...


  • Please log in to reply
1 reply to this topic

#1 bassplaya4string

bassplaya4string
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 26 October 2006 - 03:34 AM

I have a quiz that has 10 questions. When the user fills out all of the radio buttons, an evaluation will come up along with the correct answers. my problem is every time someone completes a quiz, under the evaluation the quiz is still visible here is my code
<?php

$questions = array($_POST["Q_1"], $_POST["Q_2"], $_POST["Q_3"], $_POST["Q_4"], $_POST["Q_5"], $_POST["Q_6"], $_POST["Q_7"], $_POST["Q_8"], $_POST["Q_9"], $_POST["Q_10"],);

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form	
} else {
	$i = 0;
	$throw = false;
	while ($i < 10){
		if ($questions[$i] == null) {
		$throw = true;
		}
		
	$i++;
	
	}
			
	if ($throw){
	$error = "Please answer all of the  questions.";
	
	} else {
	$score = $Q_1 + $Q_2 + $Q_3 + $Q_4 + $Q_5 + $Q_6 + $Q_7 + $Q_8 + $Q_9 + $Q_10;
	$complete = "<span class='h5'>Your score is ".$score.".</span><br />";
	$description = "<span class='h2'>EXPLANATION</span><br /><br />...
then above the form I have this...

 <font color="red"><? print ($error); ?></font><br />
					  <? print ($complete); ?><br />
					  <? print ($description); ?>

					<!-- start of form -->  
                      <form method="post" action="<? $PHP_SELF ?>">
                        <span class="h2">1. True leaders are born, not made.</span><span class="body"><br>
                          True:
                          <input value="0" name="Q_1" type="radio">
                          False:
                          <input value="1" name="Q_1" type="radio">...


#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 26 October 2006 - 03:44 AM

You can put things inside a div and then mark the div as hidden, using javascript.  I can't give details as my memory is hazy, but that approach will certainly work.

Or in PHP, you can put <? if (!isset($_POST['submit'])) { ?> <form> ... </form> <? } ?>

That will only display the form if $_POST['submit'] is not set.

I hope one of those approaches helps!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users