Page 1 of 1

Help with passing data from one form to another

Posted: Sat Feb 07, 2009 9:26 am
by zunebuggy
I want to have 5 forms. I want people to go to form1, when they complete that, they click a next button and it takes them to form 2, etc... I want to collect the data entered along the way. On one of the forms, the user will complete it and have the option of the Next button, but will also have an option of staying on that page and Adding more of the same type of data. I know I will have to hold all this in an array. Finally when the last form is complete, I want all the entered data to be combined and then sent via email to me.

I have found examples of how to send email via PHP and feel I can do that. It is passing the variables from one form to another I am having trouble with. I have tried to find tutorials to show me how, but none are like what I am doing. And I do not know how to create the code for handling the form page that allows the user to keep adding data and saving this to an array. And will I have to set a finite limit on this array or can I make it open ended and allow them to keep adding more data virtually indefinitely?

I am a VB developer that is new to PHP and just need a little help getting started.

Thank you. :D

Re: Help with passing data from one form to another

Posted: Sat Feb 07, 2009 6:27 pm
by califdon
You have 2 options: use Form variables (optionally, they can be type='hidden', if you don't want them to appear to the user) and recover them on the next page as $_POST[] variables; OR use session variables.

For the first option, you need to have an HTML Form defined on the earlier page:

Code: Select all

...
<form name='myForm1' method='post' action='myurl.php'>
<input type='text' name='LastName' /><br />
<input type='text' name='FirstName' /><br />
<input type='hidden' name='password' />
<input type='submit' value='Submit'></form>
...
Then, in myurl.php, you need:

Code: Select all

...
<?php
$LastName = mysql_real_escape_string($_POST['LastName']);
$FirstName = mysql_real_escape_string($_POST['FirstName']);
$password = mysql_real_escape_string($_POST['password']);
...
?>
 
In both cases, you can use arrays, and yes, you don't have to declare an upper size limit for an array. The syntax to add one more element to an array is simple, just omit the index:

Code: Select all

$test=Array();
$test[0]="A";
$test[1]="B";
$test[2]="C";
$test[]="D";
$test[]="E";
 
The last 2 lines add $test[3] and $test[4], just as if the index had been specified, as it was for 0, 1, and 2.