Series of questions

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Daz Wilde
Forum Newbie
Posts: 9
Joined: Sun Oct 02, 2005 12:02 pm

Series of questions

Post by Daz Wilde »

I want to do a site where i can ask a series of questions for booking an advert

So for example:

Pick Advert Type: small - medium - large

back next

(then it moves on to the next page)

Type Description: [textfield]

back next

(then it moves on to the next page)

Enter you details: [textfield] - [textfield] - [textfield]

Submit

Then all the information is sent through via email just like a normal contact form.

Just like placing an ad on autotrader..... would this be easy to do???

Cheers
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

Why don't you just create a form and send it to another page that will send the emai?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ya, you could make a single page with all of this stuff in one form, that it then emails. Or, you could make the page only show one question at a time, but keep posting the previous data so that at the end, it has all the data. Or, you could make the page store each question in a cookie/session, which is then read at the end and emailed.

Long story short - it's certainly doable.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Daz Wilde
Forum Newbie
Posts: 9
Joined: Sun Oct 02, 2005 12:02 pm

Post by Daz Wilde »

pickle wrote:Ya, you could make a single page with all of this stuff in one form, that it then emails. Or, you could make the page only show one question at a time, but keep posting the previous data so that at the end, it has all the data. Or, you could make the page store each question in a cookie/session, which is then read at the end and emailed.

Long story short - it's certainly doable.
I'd prefer to do it on a page by page question by question as i dont want to bombard them with all the questions on one page.

How do you recommend doing it then?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Well, you can either use forms, sessions or cookies

Using forms, you'd have to gather all the relevant POST data, and put them in as hidden form elements on the current page. For example, if the first question asks them for their name, then when the second question is loaded, you'd have to pull the first name field from $_POST, and store it as a hidden field in the form that asks the second question. Then, when the second question is submitted, the data from the first question is submitted too.

Using sessions, you'd have to call session_start() beginning of the page, then store any POST data in a session variable. Then when you're ready to email, just use the session data. This is probably the way I'd do it.

Using cookies, you'd have to store each question in either it's own cookie, or concatenate all the questions into a string and store it in a cookie. This would break if the user had cookies turned off though.


Using sessions is probably the way to go.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Daz Wilde
Forum Newbie
Posts: 9
Joined: Sun Oct 02, 2005 12:02 pm

Post by Daz Wilde »

pickle wrote:Well, you can either use forms, sessions or cookies

Using forms, you'd have to gather all the relevant POST data, and put them in as hidden form elements on the current page. For example, if the first question asks them for their name, then when the second question is loaded, you'd have to pull the first name field from $_POST, and store it as a hidden field in the form that asks the second question. Then, when the second question is submitted, the data from the first question is submitted too.

Using sessions, you'd have to call session_start() beginning of the page, then store any POST data in a session variable. Then when you're ready to email, just use the session data. This is probably the way I'd do it.

Using cookies, you'd have to store each question in either it's own cookie, or concatenate all the questions into a string and store it in a cookie. This would break if the user had cookies turned off though.


Using sessions is probably the way to go.
Looks like sessions is the best way your right.

As i am just a newbie though it seems pretty difficult - i'm just used to single page forms, do you have a template i could work off or know of one mate?

Thanks again!!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

No template, but here's some pseudo-code:

Code: Select all

<?PHP

session_start();
$_SESSION['question1'] = $_POST['question1'];

?>
<form name = 'question2form...>
<input type = "text" name = "question2">
<input type = 'submit'>
</form>
This kind of thing should be done on every page, for every question. On the last page, just loop through every $_SESSION variable you've set, and throw it into your email.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Daz Wilde
Forum Newbie
Posts: 9
Joined: Sun Oct 02, 2005 12:02 pm

Post by Daz Wilde »

pickle wrote:No template, but here's some pseudo-code:

Code: Select all

<?PHP

session_start();
$_SESSION['question1'] = $_POST['question1'];

?>
<form name = 'question2form...>
<input type = "text" name = "question2">
<input type = 'submit'>
</form>
This kind of thing should be done on every page, for every question. On the last page, just loop through every $_SESSION variable you've set, and throw it into your email.
Cheers mate but its baffled me now, not sure ill be able to suss this out.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

It's not really that difficult.. just think of it in english.

Whenever someone answers one of your form questions, and then submits that answer, it will be stored in a variable. $_POST['thequestionanswered'] is this variable.

Then you're using a big container ( we'll call it $_SESSION ;) ) to store this variable in.

Each time a question gets answered, you store it's variable in the container. Then when you're ready to submit all of the information, after all of the questions get answered.. grab your data from your container! Just like it was submitted all at once.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Daz Wilde
Forum Newbie
Posts: 9
Joined: Sun Oct 02, 2005 12:02 pm

Post by Daz Wilde »

scrotaye wrote:It's not really that difficult.. just think of it in english.

Whenever someone answers one of your form questions, and then submits that answer, it will be stored in a variable. $_POST['thequestionanswered'] is this variable.

Then you're using a big container ( we'll call it $_SESSION ;) ) to store this variable in.

Each time a question gets answered, you store it's variable in the container. Then when you're ready to submit all of the information, after all of the questions get answered.. grab your data from your container! Just like it was submitted all at once.
Mmmmm you make it sound so simple....

I'll have a try but its bound to go wrong somewhere?

It should only be about 3 pages with different questions on.

If im struggling you'll have to help.
Post Reply