Andrew Green
11-04-2005, 04:24 PM
Rather simple way of sending a form to your e-mail, validation is limited to checking if anything was entered. Retains entered fields if it needs to ask for missing ones. Should get the ideas across.
<?php
// pull the posts out to keep things simple. If nothing has been posted they will just be NULL.
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
If ($_POST['Submit']=="Submit"){
if(($firstname=="")||($lastname=="")||($email=="")) //Quick check to see if all the fields are filled in, if not...
{
echo "<p style='font-size:120%;color:red'>Error: You must complete ALL required fields.</p>";
$_POST['Submit']="error";
}
else { //If they where, send the e-mail, say thank you and redirect back to the main page
header("Refresh: 3; URL=index.php"); // Rediercts back to index.php after 3 seconds
// A little table to keep the information being sent neat
$message="
<html>
<body>
<table>
<tr>
<td>First Name: </td>
<td>$firstname</td>
</tr>
<tr>
<td>Last Name: </td>
<td>$lastname</td>
</tr>
<tr>
<td>E-Mail: </td>
<td>$email</td>
</tr>
</table>
</body>
</html>
";
$headers = "MIME-Version: 1.0\r\n".
"Content-type: text/html; charset=iso-8859-1\r\n".
"Date: ".date("r")."\r\n";
//set the type to html, charset and the date.
mail("a@b.c", "Message title", $message, $headers); // Send the message (to - title - message - headers)
//Say thank you for filling it out and wait for the refresh
echo "<html><body>
<br/><br/><h3 style='text-align:center'>Thank You for your Registration</h3>
<p style='text-align:center'>A representitve will be contacting you soon to confirm Registration and arrange payment.</p>
<p style='text-align:center'>You are being re-directed back to the "Designing Inclusive Schools" event page.</p>
<p style='text-align:center'>If you are not re-directed please <a href='index.php'>click here to continue</a></p></body></html>";
}
}
//if nothing has been submitted, or an error got set above, do this:
// setting it to error gives you the option of marking fields that they missed or anything along those lines...
//The posts where pulled out above, so they will be placed in the form if they where entered already.
If ($_POST['Submit']!="Submit"){
echo"
<html>
<body>
<h3>Sign up!</h3>
<form name='disreg' method='post' action='form.php'>
<table>
<tr>
<td>First Name:</td>
<td><input type='text' name='firstname' width='40' value='$firstname'></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type='text' name='lastname' width='40' value='$lastname'></td>
</tr>
<tr>
<td>E-Mail: </td>
<td><input type='text' name='email' width='40' value='$email'></td>
</tr>
</table>
<p>
<input type='submit' name='Submit' value='Submit'>
</p>
</form>
</body>
</html>
";
}
?>
<?php
// pull the posts out to keep things simple. If nothing has been posted they will just be NULL.
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
If ($_POST['Submit']=="Submit"){
if(($firstname=="")||($lastname=="")||($email=="")) //Quick check to see if all the fields are filled in, if not...
{
echo "<p style='font-size:120%;color:red'>Error: You must complete ALL required fields.</p>";
$_POST['Submit']="error";
}
else { //If they where, send the e-mail, say thank you and redirect back to the main page
header("Refresh: 3; URL=index.php"); // Rediercts back to index.php after 3 seconds
// A little table to keep the information being sent neat
$message="
<html>
<body>
<table>
<tr>
<td>First Name: </td>
<td>$firstname</td>
</tr>
<tr>
<td>Last Name: </td>
<td>$lastname</td>
</tr>
<tr>
<td>E-Mail: </td>
<td>$email</td>
</tr>
</table>
</body>
</html>
";
$headers = "MIME-Version: 1.0\r\n".
"Content-type: text/html; charset=iso-8859-1\r\n".
"Date: ".date("r")."\r\n";
//set the type to html, charset and the date.
mail("a@b.c", "Message title", $message, $headers); // Send the message (to - title - message - headers)
//Say thank you for filling it out and wait for the refresh
echo "<html><body>
<br/><br/><h3 style='text-align:center'>Thank You for your Registration</h3>
<p style='text-align:center'>A representitve will be contacting you soon to confirm Registration and arrange payment.</p>
<p style='text-align:center'>You are being re-directed back to the "Designing Inclusive Schools" event page.</p>
<p style='text-align:center'>If you are not re-directed please <a href='index.php'>click here to continue</a></p></body></html>";
}
}
//if nothing has been submitted, or an error got set above, do this:
// setting it to error gives you the option of marking fields that they missed or anything along those lines...
//The posts where pulled out above, so they will be placed in the form if they where entered already.
If ($_POST['Submit']!="Submit"){
echo"
<html>
<body>
<h3>Sign up!</h3>
<form name='disreg' method='post' action='form.php'>
<table>
<tr>
<td>First Name:</td>
<td><input type='text' name='firstname' width='40' value='$firstname'></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type='text' name='lastname' width='40' value='$lastname'></td>
</tr>
<tr>
<td>E-Mail: </td>
<td><input type='text' name='email' width='40' value='$email'></td>
</tr>
</table>
<p>
<input type='submit' name='Submit' value='Submit'>
</p>
</form>
</body>
</html>
";
}
?>