Confirmatoin page and email submission

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gamz
Forum Newbie
Posts: 1
Joined: Fri Nov 03, 2006 1:41 pm

Confirmatoin page and email submission

Post by gamz »

Hello fellow php devs - i've got some code i'm having trouble implementing in my page

I've managed to put together a php form where I take the results of the submission, put them in a session where it takes the user to a confirmation prompt. At this prompt, the user will validate their information and will then have the option to submit to my select email recipient, make modifications, and print the page.

The issue i'm having is before the user click submit on the confirmation prompt, it not only specifies the submission has been made, but it automatically sends the confirmation letter. What I want to do is try and suppress the email being sent before the user clicks on the submit button.

Here's what i've got so far -

Code: Select all

<?php
    session_start();
	if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit']) )
?>	
	<html>
	<head>
	<style type="text/css">
	<!--
	.style4 {font-family: Arial; font-size: 10px; font-weight: bold; }
	.style6 {font-family: Arial; font-size: 10px; color: #000066; }
	-->
	</style>
	</head>
	<title>Bippity Boppity Boo Party Set-Up Form</title>
	<style type="text/css">
	<!--
	body {
		margin-top: 0px;
		background-color: #384E70;
	}
	-->
	</style>
	
	<body>
	<div align="center">
	  <table width="691" height="176" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
		<!--DWLayoutTable-->
		<tr>
		  <td width="243" height="71" valign="top"><img src="images/Form_header_01.jpg" width="243" height="142" /></td>
		<td width="231" valign="top"><img src="images/Form_header_02.jpg" width="231" height="142" /></td>
		<td width="217" height="142" valign="top"><img src="images/Form_header_03.jpg" width="217" height="142" /></td>
		</tr>
		<tr>
		  <td height="71" colspan="3" valign="top"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
			<tr>
			  <td>
	<h1 align="center">Bippity Boppity Boo Party Reservation<br>
	  Confirmation Page
	  <body>
	</h1>
	<form name="bc" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
	<table width="100%" border="0" cellspacing="1" cellpadding="1">
	  <tr>
		<td width="30%" class="style4"><label>
		  <div align="right">Representative Name:</div>
		</label></td>
		<td width="70%" class="style6"><?php $rname=$_SESSION['rname']; echo "$rname";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">Representative Phone Number:</div>
		</label></td>
		<td class="style6"><?php $rnumber=$_SESSION['rnumber']; echo "$rnumber";?>    </td>
	  </tr>
	</table>
	<br>
	<table width="100%" border="0" cellspacing="1" cellpadding="1">
	  <tr>
		<td width="30%" class="style4"><label>
		  <div align="right">Address:</div>
		</label></td>
		<td width="70%" class="style6"><?php $address=$_SESSION['address']; echo "$address";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">City:</div>
		</label></td>
		<td class="style6"><?php $city=$_SESSION['city']; echo "$city";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">State:</div>
		</label></td>
		<td class="style6"><?php $state=$_SESSION['state']; echo "$state";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">Zip:</div>
		</label></td>
		<td class="style6"><?php $zip=$_SESSION['zip']; echo "$zip";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">Location:</div>
		</label></td>
		<td class="style6"><?php $location=$_SESSION['location']; echo "$location";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">Date:</div>
		</label></td>
		<td class="style6"><?php $date=$_SESSION['date']; echo "$date";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">Start:</div>
		</label></td>
		<td class="style6"><?php $start=$_SESSION['start']; echo "$start";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">End:</div>
		</label></td>
		<td class="style6"><?php $end=$_SESSION['end']; echo "$end";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">Children:</div>
		</label></td>
		<td class="style6"><?php $kids=$_SESSION['kids']; echo "$kids";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		<div align="right">Adults:</div>
		</label></td>
		<td class="style6"><?php $adults=$_SESSION['adults']; echo "$adults";?>    </td>
	  </tr>
	  <tr>
		<td class="style4"><label>
		  <div align="right">School:</div>
		</label></td>
		<td class="style6"><?php $school=$_SESSION['school']; echo "$school";?>    </td>
	  </tr>
	</table>
	<br>
	
	<p>
	  <input name="back" id="back" type="button" class="style1"  value="Back" onClick="history.go(-1);return true;">
	  <input name="submit" type="submit" class="style1" id="submit" value="Submit"> 
	  <input type="button" value=" Print this page "
	onclick="window.print();return false;" /></p>
	
	</form>
	<?php 
         $recipient = 'my@email.com';  //I change this to my real email address
         $subject = "Bippity Boppity Boo Confirmation";
         $from = stripslashes($_SESSION['rname']);
         $numbr = stripslashes($_SESSION['rnumber']);
         $msg = "Message sent by $from\n";
         $msg.= "Representative Phone Number: $numbr\n";
         $msg.= "<p>Credit card information: ";
         $msg.= "<p>\nAddress: ".$_SESSION['address'];
         $msg.= "\nCity: ".$_SESSION['city'];
         $msg.= "\nState: ".$_SESSION['state'];
         $msg.= "\nZip: ".$_SESSION['zip'];
         $msg.= "<p>\nEvent Date: ".$_SESSION['date'];
         $msg.= "\nStart Time: ".$_SESSION['start'];
         $msg.= "\nStart Time: ".$_SESSION['end'];
         $msg.= "\nChildren: ".$_SESSION['kids'];
         $msg.= "\nAdults: ".$_SESSION['adults'];
         $msg.= "<p>\nSchool Name: ".$_SESSION['school'];
         if (mail($recipient,$subject,$msg))
         {
            echo "<p>Your reservation has been sent to the selected Bippity Boppity Boo Representative in that area.  They will be in contact with you to confirm your reservation.  Thank you!</p>";
            echo nl2br($msg);
         } else
            echo "An unknown error occurred.";
		?>
         }
    }
		</td>
			</tr>
		  </table></td>
		</tr>
	  </table>
	</div>
	</body>
	</html>
Please review my code and suggest the changes I should make to get this thing running properly. Thanks in advance.
Post Reply