I have a little problems with storing values from forms. This is what I am trying to do.
I have quite a large form and am trying to split into different sections (pages.)
So lets says I have a variable called section that track the form processing and I have a form structure that is the shell for the form. The I choose which for to display according to the value in the section variable.
as below
Code: Select all
$stage =1;
if (isset ($_POSTї'stage']))
{
$stage = $_POSTї'stage'];
}
// Logon details
$form_1 = " <tr>
<th colspan='2'>Logon Details.</th>
</tr>
<tr>
<td>Email address:</td>
<td><input type='text' name='email_1' value=".$email_1."></td>
</tr>
<tr>
<td>Re-type Email:</td>
<td><input type='text' name='email_2' value=".$email_2."></td>
</tr>
<tr>
<td>Password: </td>
<td><input type='password' name='pass_1'></td>
</tr>
<tr>
<td>Re-type Password: </td>
<td><input type='password' name='pass_2'></td>
<tr>";
// Contact details and personal details.
$form_2 = "<tr>
<td width='32%'>First Name</td>
<td><input type='text' name='fname' value=".$fname."></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type='text' name='lname' value=".$lname."></td>
</tr>";
$form_3 = "";
$form_4 = "";
$form_5 = "<tr>
<th colspan='2'>Conatact Details.</th>
</tr>
<tr>
<td>Full Name:</td>
<td>".$fname." ".$lname."</td>
</tr>";
/* POSTї'stage'] variable : control the registration process
* 1: Beginning stage : Login details
* 2: Contact details
* 3: Personal details
* 4: Ideal Partner
*/
$form_struct = "<table width='70%' border='0' align='center'>
<tr>
<td>
<form action=".$PHP_SELF." method='post' name='mem_reg'>
<table width='100%' border='0'>
";
$nav_forward = "<input type='submit' name='NF' value='Next'>
<input type='hidden' name='stage' value='".++$stage."'>";
$nav_back = "<input type='button' name='NB' value='Back' onclick='history.go(-1)'>";
if ($stage == 1)
$form_struct .= $form_1;
else if ($stage == 2)
$form_struct .= $form_2;
else if ($stage == 3)
$form_struct .= $form_3;
else if ($stage == 4)
$form_struct .= $form_4;
else if ($stage == 5)
$form_struct .= $form_5;
$form_struct .= "
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>";
$form_struct .= " </td>
<td>";
$form_struct .=$nav_forward;
$form_struct .= "</td></tr>";
$form_struct .= "
</table>
</td>
</tr>
</table>";
$body = "<td valign=top width=100%>
".$form_struct."
</form>
</td>";Coming to the problem now.
The that I am having is that, although I try to store the values entered onto the variables. I can only hold them for next form I enter to then I loose it.
So if for example I enter my Name in form_2 I can view it on form_4 but as soon as I get to form_4 the value stored on the $fname and $lname variables are lost.
I just can't get my head round it as to why it does that.
I even tried putting conditions on the top of the page. That for example:
Code: Select all
if (isset($_POSTї'fname']))
{
$fname = $_POSTї'fname'];
}I think i will stop writing cause I think I get confusing (to you guys and myself
Any help would be highly appreciated.
Thx