Forum Moderators: coopster

Message Too Old, No Replies

Problem with form generating another form

         

giefe

8:30 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



I have a form that once users click "Submit" generates a page with additional options for users. How do I get to email the results from the first and second page at the same time? Right now I'm getting two emails: one with the results from the first page and one only with the second...

Help!

PHP_Chimp

9:09 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sessions [uk2.php.net] would be your best bet.

giefe

12:37 am on Oct 18, 2007 (gmt 0)

10+ Year Member



Can you please give me an example?

PHP_Chimp

7:27 am on Oct 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok a basic example-

page1.php


<?php
session_start();
if ($_POST) {
$_SESSION['var1'] = $_POST['var1'];
$_SESSION['var2'] = $_POST['var2'];
}
else {
echo <<<FORM
my form code in here
FORM;
}
?>

page2.php

<?php
session_start();
if ($_POST) {
$_SESSION['var3'] = $_POST['var3'];
$_SESSION['var4'] = $_POST['var4'];
$to = $_SESSION['var1'];
$sub = $_SESSION['var2'];
$body = $_SESSION['var3'];
$headers = $_SESSION['var4'];
mail($to, $sub, $body, $headers);
/*
In this example you dont need any of the second set of $_SESSION calls, as the $_POST variables are on that page.
You also dont need the $body and $header calls, as these could just be substituted for the actual variables in the mail function.
However it does show that you could then use all $_SESSION variables in a third page.
Have a play and you may want to print_r($_SESSION) to see what variables you have available in the session array on each page.
*/
}
else {
echo <<<MOREFORM
even more form code
MOREFORM;
}

giefe

1:26 pm on Oct 18, 2007 (gmt 0)

10+ Year Member



Thank you very much!

PHP_Chimp

1:45 pm on Oct 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If this is your first look at sessions then have a read of the session manual, as there are some links to good articles about how to make your sessions secure. Wikipedia has another few articles and there are loads of things on the web.

As depending on what your form is used for security may or may not be a problem.

There have been a number of discussions on this forum about securing sessions, so it may well be worth searching through and reading them.