Hello,
I'm working on a project which is basically like one of those "what TV character are you?" tests; however it's a little more complex than that. I'm trying to build a "make-your-own manifesto" questionnaire. The question arch will change depending on the answer given to the last question - so if they say their favorite animal is a dog, it will ask about dog breeds, and if they say cat, it will ask about cat breeds. This means the questions would have to either be on separate pages (which are what I've got right now) or use some sort of JavaScript coding (?).
I have the basics of this part relatively figured out, or at least I have a working example. Not sure if it will work with what else I need it to do though.
Here's an example of my starting page:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Make Your Own Manifesto Section 1</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="process.php">
<span id="name">
<label>Name of the Revolution:
<input type="text" name="rev_name" id="rev_name" />
</label>
</span>
<p>What is your cause?<br />
<label>
<input type="radio" name="cause" value="0" id="cause_0" />
Art</label>
<br />
<label>
<input type="radio" name="cause" value="1" id="cause_1" />
Gender</label>
<br />
<label>
<input type="radio" name="cause" value="2" id="cause_2" />
Technology</label>
<br />
<label>
<input type="radio" name="cause" value="3" id="cause_3" />
Religion</label>
</p>
<p>
<label>
<input type="submit" name="submit" id="submit" value="Next" />
</label>
<br />
</p>
</form>
<p>Please note, if your cause falls under any other category (sexuality or race for example) please come back later - we are not presently enlightened enough to be of assistance - But we're working on it. However, if you have feedback for us, please email us</p>
</body>
And This is the corresponding page - the rest of the questionnaire is pretty much identical to this minus the actual questions, etc. being different:
$cause = $_POST['cause'];
//these are the if/thens based on the answers given from a form on the main HTML page
if ($cause == "0")
//this is setting up the next questions to be asked if their first answer was "art"
{
echo '<form method="post" action="processq3b1.php">'.
'<p>Do you want art to become different from what it is, return to the classic forms, or neither?<br />'.
'<label>'.
'<input type="radio" name="change" value="0" id="0" />'.
'Change is Good</label>'.
'<br />'.
'<label>'.
'<input type="radio" name="change" value="1" id="1" />'.
'Why fix it if it was never broken? The Classical artists had it right.</label>'.
'<br />'.
'<label>'.
'<input type="radio" name="change" value="2" id="2" />'.
'Neither. Next Question.</label>'.
'<br />'.
'</p>'.
'<p>'.
'<label>'.
'<input type="submit" name="submit" id="submit" value="Next" />'.
'</label>'.
'<br />'.
'</p>'.
'</form>';
}
//next questions if their original answer was "gender"
elseif ($cause == "1") {
echo '<form id="form2" name="form2" method="post" action="processq3b2.php">'.
'<p>Do you consider gender to be binary or fluid?<br />'.
'<label>'.
'<input type="radio" name="binary" value="0" id="0" />'.
'there are only two combinations of chromosomes. Ergo, a binary setup. </label>'.
'<br />'.
'<label>'.
'<input type="radio" name="binary" value="1" id="1" />'.
'Nothing is ever black & white. Gender is more than just man and woman.</label>'.
'<br />'.
'</p>'.
'<p>'.
'<label>'.
'<input type="submit" name="submit" id="submit" value="Next" />'.
'</label>'.
'<br />'.
'</p>'.
'</form>';
}
//next questions if their original answer was "technology"
elseif ($cause == "2") {
echo '<form id="form3" name="form3" method="post" action="processq3b3.php">'.
'<p>Is technology a good thing or a bad thing?<br />'.
'<label>'.
'<input type="radio" name="goodtech" value="0" id="good" />'.
'Technology is the way to go. </label>'.
'<br />'.
'<label>'.
'<input type="radio" name="goodtech" value="1" id="bad" />'.
'Carpal tunnel, messed up back and eyes, no social skills... the future is not friendly</label>'.
'<br />'.
'</p>'.
'<p>'.
'<label>'.
'<input type="submit" name="submit" id="submit" value="Next" />'.
'</label>'.
'<br />'.
'</p>'.
'</form>';
}
//next questions if their original answer was "religion"
elseif ($cause == "3") {
echo '<form id="form4" name="form4" method="post" action="processq3b4.php">'.
'<p>Are you following any form of established religion?<br />'.
'<label>'.
'<input type="radio" name="established" value="0" id="yes" />'.
'At least one other person believes what I´m fighting for. </label>'.
'<br />'.
'<label>'.
'<input type="radio" name="established" value="1" id="no" />'.
'I am making my own religion</label>'.
'<br />'.
'</p>'.
'<p>'.
'<label>'.
'<input type="submit" name="submit" id="submit" value="Next" />'.
'</label>'.
'<br />'.
'</p>'.
'</form>';
}
//this is a failsafe in case no form info was sent from the first page, or someone links directly here.
else {
echo 'Sorry, this is not the beginning of this questionnaire. <a href="myomanifesto.html">click here</a> to start from the beginning.';
}
I also would like the answers that are given to be stored either in the GET variables, or by writing into a temporary table in a MySQL database - so that at the end of the quiz, each given answer will be used to pull up a specific quote from a different database table (for example if they say they like dogs, and then they like the color green, it would draw up a quote for dogs in the first section instead of cats, and then the second section would draw up the quote assigned to green instead of red or blue.
Hence the "manifesto" will be created by combining quotes from various existing manifestos based on the results of the answers given by the user.
I know the big part I need to work on is the database side. I'm very fuzzy on what can be done and how to do it there. I am working on it, I'm just hoping I can find some reference material related to what I'm trying to do instead of having to build it all from the ground up. I can't be the first person who has tried to do this, right? Uh....right....?
I've tried looking at those quiz builder programs. Unfortunately none of the ones I have looked at deal with either the changing questions, or with creating final result pages the way I'm trying to. They usually only keep a single score or else add points to one of ~10 variable outcomes. None of them make piecemeal results based on the answers.
To boil all this down, does anyone have any examples of coding that does something similar to what I'm trying to do so I can use it as a reference/ adapt it to do what I want? Is there a cleaner way of asking the questions? Like, a javascript example or something similar that could keep it all on one page, or something? I keep thinking that keeping all the coding on one page would make it easier to reference the database, am I right in assuming that?
Sorry for such a long post, and thanks a million to anyone who made it to the end and has some ideas.