View Full Version : One confirmation email, two different forms

01-27-2004, 03:58 AM
Hi everyone,
I am totally new in web programming. Maybe my question sounds so silly for some of you, but i just wanna ask how to program forms in php which will accept multiple steps? For example form 1 post to form 2 then the consolidated results from both forms are posted via one email to the user? Basically i have a registration form, and then a billing form. So, i will need to send an email to the user about all the information that they have input in both forms. Currently i am using two forms which will send two different emails to the user. So, can anyone tell me how can i send only one email but the inputs are from two different forms? Thank you in advance :o

01-27-2004, 09:53 AM
So many options. I briefly described them here:

The easiest sollution is just to include them as hidden formfields inside your second form. If this second form then is posted, you can access all formdata in the same way.

suppose form 1 contains a textfield named firstname. Like
echo('<input type="text" name="firstname" />');
then inside form 2 you get
echo('<input type="hidden" name="firstname" value="' . $_POST['firstname'] . '" />');

Inside the page where you post form 2 to, you can access this formfield just like the other formfields of form 2 ----> $_POST['firstname']

If you want this a bit more efficient, then you can automatically generate the hidden formfields by looping thruogh the form-collection when you build the page with form 2 in it. Like

if ($varName != 'submit')){
/* supposing your submitbutton of form 1 is called like that.
you could also add other fields you don't want to drag along */
$hidden .= ('<input type="hidden" name="'. $varName .'" value="' . $value . '" />');
echo $hidden ;

which will create a hidden formfield inside form 2 + will store the entered data in it, for each formfield of form 1 (except the submitbutton or other fields you exclude.

01-27-2004, 03:17 PM
I was thinking of using session. But since i am very new in php, i dont know how to start. Can you advice me on this? Thank you in advance

01-27-2004, 03:36 PM
Did you check the link i posted (my frst post inthere)?

Why uses sessions? It's only data the user submitted himself and you only need to drag it along for one page, so hiddenformfields are probably the easiest.

You could use sessions like

$_SESSION['firstname']= $_POST['firstname'] ;

and then access it like

$firstname = $_SESSION['firstname'] ;

==> on each page where you use sessionvariables, put session_start() at the top of your php-page !!

When you use sessionvariable, you could also use a loop, but then you need to use variable variablenames. Like

foreach ($_POST as $varName => $value){
if ($varName != 'submit')){
/* supposing your submitbutton of form 1 is called like that.
you could also add other fields you don't want to drag along */
$_SESSION[{$varName }] = $value ;

This creates a new sessionvariable for each formfield (except the submitbutton) and stores the posted formfields value in it. The sessionvariables are then named the same as the formfields.