I have a three page event registration form. The second page (shown below) summarizes the selections made on a page 1, totals the bill, and emails the information. The user should then be directed to a third page that provides a "your registration has been sent" message along with a button to conncet to Paypal.
Problem: As I have written the code (shown below), the second page showing the total is bypassed (although it continues to send the email appropriately) and the user is taken directly to the third page.
Question: Is there a way to use the submit button to control the redirect so that the user can linger on the summary page, be redirected when he hits submit, and keep the email function? Do I need to use sessions to accomplish this?
Code is below. Thanks in advance for any help provided.
<?php
//Turn on output buffering.
ob_start();
?>
<!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=iso-8859-1" />
<title>Registration Summary</title>
</head>
<body>
<?php // summary_2.php / This script receives the data from test_2.php, totals and emails it./
//Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
//Process the email.
if (array_key_exists('send', $_POST)){
$to = 'abc@aol.com';
$subject = '2008 Registration';
// process the $POST variables
$firstname = $POST['firstname'];
$lastname = $POST['lastname'];
$address = $POST['address'];
$city = $POST['city'];
$state = $POST['state'];
$zip = $POST['zip'];
$phone = $POST['phone'];
$email = $POST['email'];
$membertype = $POST['membertype'];
$guestnumber = $POST['guestnumber'];
$guestname1 = $POST['guestname1'];
$guestname2 = $POST['guestname2'];
$guestname3 = $POST['guestname3'];
$bustrip = $POST['bustrip'];
$event = $POST['event'];
$cardholder = $_POST['cardholder'];
//Calculate the total.
$total = $membertype + $guestnumber + $bustrip + $event;
//Show the results on screen
print "This is a summary of your selections:<br />
First Name: $firstname <br />
Last Name: $lastname <br />
Street Address: $address <br />
City: $city <br />
State: $state <br />
Zip = $zip <br />
Phone = $phone <br />
Email = $email <br />
Registration Fee: $membertype <br />
Guests: $guestnumber <br />
Guest Name= $guestname1 <br />
Guest Name= $guestname2 <br />
Guest Name = $guestname3 <br />
Bus Tickets: $bustrip <br />
Field Trip Fees: $event <br />
Name on Credit Card: $cardholder <br />
Total cost: $total";
/ Build the message from the form data and email it./
$message = "First Name: $firstname\n\n";
$message .= "Last Name: $lastname\n\n";
$message .= "Address: $address\n\n";
$message .= "City: $city\n\n";
$message .= "State: $state\n\n";
$message .= "Zip: $zip\n\n";
$message .= "Phone: $phone\n\n";
$message .= "Email: $email\n\n";
$message .= "Member Status: $membertype\n\n";
$message .= "Guest Fees: $guestnumber\n\n";
$message .= "Guest Name: $guestname1\n\n";
$message .= "Guest Name: $guestname2\n\n";
$message .= "Guest Name: $guestname3\n\n";
$message .= "Bus Tickets: $bustrip\n\n";
$message .= "Guest Event: $event\n\n";
$message .= "Name on Credit Card: $cardholder\n\n";
?>
<form id=confirm method="post" action="">
<input name= "send" type="submit" value="Confirm Registration Information" />
</form>
<?php
//send it
$mailSent = mail($to, $subject, $message, $additionalHeaders);
if ($mailSent) {
header('Location: http://www.abc.org/reg_test.php');
exit;
}
}
ob_end_flush();
?>
</body>
</html>