Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-09-2012, 08:39 PM   PM User | #1
BHayes
New to the CF scene

 
Join Date: Apr 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
BHayes is an unknown quantity at this point
Cool Combining multiple forms to send in one E-mail

I'm really stumped on this problem.
Using php I have created a form in Dreamweaver that is a timed test. It goes like this:
Page 1: Name/ID
Page 2/3/4: Test questions
Page 5: Survey
Each time they submit the results to go to the next page, it sends me an e-mail of the results. Problem is that it sends a separate e-mail for each page, so I get 5 separate e-mails for each person that takes the test. Can someone point me in the right direction on what I can do to combine all of the results into 1 e-mail? I have looked into session variables and arrays but I'm not sure what to do.

This is what I envision to do but let me know if there's a better way to do it.

So option 1)
Form 1 submit ---> Store results in Form 2 - Form 2 Submit ---> Store results from F1 & F2 - Form 3 Submit ---> Sends email of results from F1, F2, and F3

OR

Form 1 Submit ---> Store results in Form 3
Form 2 Submit ---> Store results in Form 3
Form 3 Submit ---> Email results of Form 1, 2, and 3
BHayes is offline   Reply With Quote
Old 04-10-2012, 04:33 AM   PM User | #2
ShaneC
Codeasaurus Rex


 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 659
Thanks: 31
Thanked 100 Times in 94 Posts
ShaneC is on a distinguished road
You've got the solution to the problem: you need to store the form data.

Now, judging by the fact you're asking the question, you're probably not sure which way to store it.

You've got three main (read: sensible) ways: Cookies, Sessions, and Database.

Database is the secure and highly scalable option, but you'll need to invoke sessions to do it. Doesn't sound like the optimal choice for your situation.

Cookies are fun, but they are dependent on cookies being enabled by the host machine (as are sessions, frankly, to an extent).

Sessions are probably going to be your best bet.

Here's a good looking tutorial that should tell you just how to store this information from one page to another:

http://www.tizag.com/phpT/phpsessions.php


Your adaptation in a nutshell (but read the tutorial before you try to analyze this):

PHP Code:
session_start();

// On page 1
$_SESSION['mySurvey'] = array( "data" => array() );  // Create an array to put our data in. We'll use the format $_SESSION['mySurvey']['data']['survey_one']

// Pages 1 through final

// Now let's say you've only got one question on this page and the answer is stored in $answer.
// Let's make our result array

$results = array( "Question could go here as the key" => $answer );

// Now store your results in the session
$_SESSION['mySurvey']['data']['survey_one'] = $results
Then, on the final page, you can iterate over your results (possibly using a foreach loop, and then format it however you'd like.
__________________
Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com

Last edited by ShaneC; 04-10-2012 at 04:37 AM..
ShaneC is offline   Reply With Quote
Users who have thanked ShaneC for this post:
BHayes (04-11-2012)
Old 04-10-2012, 09:27 PM   PM User | #3
BHayes
New to the CF scene

 
Join Date: Apr 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
BHayes is an unknown quantity at this point
Awesome!
I won't be working on it again until tomorrow so I'll try it out then.

Thank you so much for getting me on track.
BHayes is offline   Reply With Quote
Reply

Bookmarks

Tags
array, email, form, php, session

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:27 AM.


Advertisement
Log in to turn off these ads.