Help with passing variables.
Posted: Wed Aug 05, 2009 6:19 am
I keep losing variables every time I try to pass them across more than 2 pages. I have tried a million different ways and still cannot find a solution. Here is my example below:
Pass.php
Pass2.php
Pass3.php
Pass4.php
On Pass4.php I would like ask a new series of questions such as phone number, budget etc..
How would I go about passing across the new variables as well as $sender_name and $sender_email to new page?
Also I have a feeling there is an easier way to achieve my ultimate goal of a mutli-page email form. If anyone has any suggestions on what im doing wrong or how to help it will be greatly appreciated!
Pass.php
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SC Form Version 1.0</title>
<script type="text/javascript" src="SCscript.js"></script>
<link rel="stylesheet" type="text/css" href="SCstyle.css" />
</head>
<body>
<form name="SCform" method="post" action="pass2.php">
<input type="hidden" name="Pass1" />
<b>Name:</b><input name="Name" type="text" />
<br />
<b>Email:</b><input name="Email" type="text" />
<br />
<input type="reset" value="Reset" name="Reset"> <input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
Code: Select all
<?php
$sender_name = $_POST['Name']; // Define Post Variable for 'Name'
$sender_email = $_POST['Email']; // Define Post Variable for 'Email'
$Pass1 = $_POST['Pass1'];
$Pass3 = $_POST['Pass3'];
// Create an empty array to hold the error messages.
$SC_Errors = array();
// If the email form input "Name" is empty
if ($sender_name=='')
// Define a variable for the error message
$SC_Errors['Name'] = 'Enter Your Name.';
// If the email form input "Email" is empty
if ($sender_email=='')
// Define a variable for the error message
$SC_Errors['Email'] = 'Enter Your Email Address.';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if (isset($Pass1)) {
if (count($SC_Errors) == 0) {
include 'pass4.php';
} else {
include 'pass3.php';
}
}
if (isset($Pass3)) {
if (count($SC_Errors) == 0) {
include 'pass4.php';
} else {
include 'pass3.php';
}
}
?>
</body>
</html>
Code: Select all
<?php
$sender_name = $_POST['Name']; // Define Post Variable for 'Name'
$sender_email = $_POST['Email']; // Define Post Variable for 'Email'
$Pass3 = $_POST['Pass3'];
// Create an empty array to hold the error messages.
$SC_Errors = array();
// If the email form input "Name" is empty
if ($sender_name=='')
// Define a variable for the error message
$SC_Errors['Name'] = 'Enter Your Name.';
// If the email form input "Email" is empty
if ($sender_email=='')
// Define a variable for the error message
$SC_Errors['Email'] = 'Enter Your Email Address.';
?>
<form name="SCform" method="post" action="pass2.php">
<input type="hidden" name="Pass3" />
<!-- Input: Name -->
<table>
<tr>
<td>
<table>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<div <?php if (!empty($SC_Errors['Name'])) echo ' class="SCinput"'; ?> align="center">
<input name="Name" type="text" value="<?php echo $_POST['Name'];?>" />
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div <?php if (!empty($SC_Errors['Name'])) echo ' class="SCerror"'; ?> align="center">
<?php if (!empty($SC_Errors['Name'])) echo '<b> '.$SC_Errors['Name'].' </b>'; ?>
</div>
</td>
</tr>
</table>
<!-- Input: Name -->
<br />
<!-- Input: Email -->
<table>
<tr>
<td>
<table>
<tr>
<td>
<b>Email: </b>
</td>
<td>
<div<?php if (!empty($SC_Errors['Email'])) echo ' class="SCinput"'; ?> align="center">
<input name="Email" type="text" value="<?php echo $_POST['Email'];?>" />
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div<?php if (!empty($SC_Errors['Email'])) echo ' class="SCerror"'; ?> align="center">
<?php if (!empty($SC_Errors['Email'])) echo '<b> '.$SC_Errors['Email'].' </b>'; ?>
</div>
</td>
</tr>
</table>
<!-- Input: Email -->
<br />
<br />
<input type="reset" value="Reset" name="Reset"> <input type="submit" name="Submit" value="Submit" />
</form>
Code: Select all
<?php
$sender_name = $_POST['Name']; // Define Post Variable for 'Name'
$sender_email = $_POST['Email']; // Define Post Variable for 'Email'
?>
<?php echo $sender_name; ?>
<?php echo $sender_email; ?>
How would I go about passing across the new variables as well as $sender_name and $sender_email to new page?
Also I have a feeling there is an easier way to achieve my ultimate goal of a mutli-page email form. If anyone has any suggestions on what im doing wrong or how to help it will be greatly appreciated!