PDA

View Full Version : PHP Questionnaire with returned results



Davehead
August 30th, 2005, 05:38 AM
Hi all,
I hope i explain it properly and clearly :

I am working on a site www.getcheaper.co.uk and the page in question is
the broadband page (http://www.getcheaper.co.uk/products/Internet+connection/).

Now, what I am needing to do, is create a questionairre in a pop-up window, or new page for that matter. I need to ask the users a specific list of requirements (connection speed, price, usage allowance etc) and when the form has been completed, I am wanting the relevant broadband packages to be displayed. Now this could be a pre-defined list , that would each fit into each category, based on selection ie: the categories we already have on the site (light, medium, heavy, business user type), or, I could assign certain packages to certain answers in the form.

The site has a DB containing all the products, and we also have a basic search faciltiy.

I have a basic PHP knowledge (the site is PHP based) and have tried searching around, but can only seem to find forms that return results via email, not actually display on the site/in the browser.

Any advice is much appreciated.

Regards,
D :be:

Ankou
August 30th, 2005, 01:42 PM
It's not too different from the tutorials that you've probably read with returning the results via email.

1. Pop open a window with JavaScript that loads the page with your PHP form full of questions.

2. The PHP form page has all your questions listed. Example:

File name: q1.php


<form action="q2.php" method="post">
<input type="text" name="user_name" value="" />
...
<input type="submit" value="Submit Form" />
</form>



the ... up there represents the list of questions that you need to ask and the related field type you need (input, textarea, select/option, etc)/


3. Then when the user submits the form you would have something like the following in file "q2.php":

File name: q2.php


if(isset($_POST["user_name"])){

$user_name = $_POST["user_name"];
// ...

// Once you have all the info from the previous for you can just echo out the data

echo "User Name: " . $user_name;

}else{
echo '<a href="q1.php" title="First Page of Questions">Please Start at Page 1</a>';
}


You're checking using isset() to make sure someone didn't just type in the url to q2.php. If they did we display a link to send them to the start page. Otherwise they reached the page after submitting the form.

Since you're working with a database you'll want to use the data submitted to make a query in order to get the information that you want to display.

The difference b/n those "mail results" tutorials that you read and what you want to do is that you're not using mail() to send the results. You're just going to echo the data out so it will display in the browser.



BTW - I omitted the other HTML and PHP code you may need - this was just an example of one way to do this.

Davehead
September 1st, 2005, 06:25 AM
Thanks a stack for all that, I will check it out.
D