I'm having problems setting up my script to direct the user to alternate pages based on their choices. I wish to have certain Global variables transfered to the new pages but this just ain't happening. Is it best to send a variable to the Header function or to the "action" part of the <form> tag?
Here is some of the code form the initial page:
<?php
if (isset($_POST['submit'])){ // Handle the form if the submit button is pressed.
$message = NULL;
// Check $name and strip any slashes
if (strlen($_POST[name]) > 0){
$name = stripslashes($_POST[name]);
} else { // if no name was entered...
$name = FALSE;
$_POST[name] = NULL;
$message .= '<p><b>You forgot to enter your name!</b></p>';
}
// Check $email
if (strlen($_POST[email]) > 6){ // a string greater than 6 characters
$email = TRUE;
} else {
$email = FALSE;
$message .= '<p><b>Please enter a valid email address!</b></p>';
}
// Check $quantity
if (strlen($_POST[quantity]) > 0){
if (is_numeric($_POST[quantity])){ // is the quantity a number
if ($_POST[quantity] > 0){
$quantity = number_format ($_POST[quantity], 0); //format to a whole number
} else {
$message .= '<p><b>please enter a value greater then zero</b></p>';
}
} else {
$message .= '<p><b>Please enter your required quantity as a whole number without comma\'s!</b></p>';
}
} else { // if no value or non-numeric was entered
$quantity = FALSE;
$_POST[quantity] = NULL;
$message .= '<p><b>Please enter your required quantity as a whole number without comma\'s!</b></p>';
}
/
if ($name && $email && $quantity){
if ($POST[location] == CD){
header ("Location:$POST[location]");
exit();
}
} else {
$message .= '<p>Please try again.</p>';
}
/
} // closing bracket for main submit button detection
$page_title = 'Product Chooser';
include ('templates/php_header.inc');
echo "<h3>$page_title</h3>";
//Print error message if there is one
if (isset($message)){
echo '<font color="red">', $message, '</font>';
}
?>
<form action="<?php $_POST['location']; ?>" method="post">
<fieldset>
<legend>Enter your information in the form below:</legend>
<p><b>Name:</b> <input type="text" name="name" size="20" maxlength="40" /></p>
<p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="60" /></p>
<p><b>Quantity:</b> <input type="text" name="quantity" size="20" maxlength="40" /></p>
<p><b>Product Required:</b><br />
<input type="radio" name="location" value="./cd_quote_form2.php" checked />CD<br />
<input type="radio" name="location" value="./ecard_quote_form.php" />e-business_card<br />
<input type="radio" name="location" value="./dvd5_quote_form.php" />DVD5<br />
<input type="radio" name="location" value="./ecard_quote_form.php" />DVD9</p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="submit" /></div>
</form>
<br><br>
<?php
include ('templates/php_footer.inc');
?>
here is the code from the 2nd page
<?php
$page_title = 'CD Quote Calculater';
include ('templates/php_header.inc');
echo "<h3>$page_title</h3>";
$quantity = $_POST['quantity'];
?>
<form action="./handle_cd_quote_form2.php" method="post">
<fieldset>
<legend>Enter your information in the form below:</legend>
<p><b>On-body print:</b> <input type="radio" name="options[]" value="on_body_yes" checked /> Yes | No <input type="radio" name="options[]" value="on_body_no" /></p>
<p><b>Packaging:</b>
<select name="options[]">
<option value="none">None</option>
<option value="double_black">Double Jewel Case (Black Tray)</option>
<option value="std_black" selected>Standard Jewel Case (Black Tray)</option>
<option value="std_clear">Standard Jewel Case (Clear Tray)</option>
<option value="slim">Slimline Jewel Case</option>
<option value="clam">Clam Shell</option>
<option value="pvc">PVC Slip Case</option>
</select></p>
<p><b>Rear Inlay:</b>
<select name="options[]">
<option value="none">Not Required</option>
<option value="one_side" selected>Printed on One Side</option>
<option value="both_side">Printed on Both Sides</option>
</select></p>
<p><b>Front Booklet:</b>
<select name="options[]">
<option value="none">Not Required</option>
<option value="one_page">One page Insert</option>
<option value="two_page" selected>Two page Insert</option>
<option value="four_page">Four page Booklet</option>
</select></p>
<p><b>Comments:</b><textarea name="comments" rows="3" cols="50"></textarea></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit Information" /></div>
</form>
<br><br>
<?php
include ('templates/php_footer.inc');
?>
Any help would be greatly appreciated.