If I could get a little direction on this would appreciate it. I'm trying to understand when data on a form is submitted, where the email is entered twice and you want to verify that the emails match and also that they are actually emails.
I have the code below that should do the exception handling but I'm not sure how to bring the variables in from the contact_form.php. I'm tring to set up the variables in the form as $email1 and $email2? Then do I do an includes on the email_check.php?
email_check.php
contact_form.phpPHP Code:<?php
class customException extends Exception
{
public function errorMessage()
{
//error message
$errorMsg =
$this->getMessage().'</b> is not a valid E-Mail address <br />
<form name="" action="contact_form.php" method="post">
<input type="button" value="Back" onClick="history.go(-1)">
</form>';
return $errorMsg;
}
}
include ('contact_form.php');
$email1 = "$_POST[email1]"; //here it should be $_POST[email]
$email2 = "$_POST[email2]";
if ($email1 == $email2){
try
{
//check if
if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE)
{
//throw exception if email is not valid
throw new customException($email);
}
echo '<"form2mail.php">'; //send to next file or thanks for filling out our form
}
catch (customException $e)
{
//display custom message
echo $e->errorMessage();
}
}
else {
?>
PHP Code:<?php
$ContactForm="<div id='content'>
<span style='position:absolute;top:-50px;'>
<form name='contact' action ='email_check.php' method='post'>
<input type='hidden' name='_From' value='from email address'>
<input type='hidden' name='_To' value='your email address'>
<input type='hidden' name='_Subject' value='FEEDBACK'>
<input type='hidden' name='_Location' value='contactus.html'>
<table width='700' cellspacing='8' cellpadding='4'>
<tr>
<td algin='left'>
<font color='white' face='arial'>First Name: </font>
<td>
<input type='text' name='fname' value=''>
<td align='left'>
<font color='white' face='arial'>Last Name:</font>
<td>
<input type='text' name='lname' value=''>
<tr>
<td algin='left'>
<font color='white' face='arial'>Address: </font>
<td>
<input type='text' name='address' value=''>
<td align='left'>
<font color='white' face='arial'>City:</font>
<td>
<input type='text' name='city' value=''>
<tr>
<td algin='left'>
<font color='white' face='arial'>State: </font>
<td>
<input type='text' name='state' value=''>
<td align='left'>
<font color='white' face='arial'>Zip:</font>
<td>
<input type='text' name='zip' value=''>
<tr>
<td align='center' colspan='4' style='color:white;font-family:arial,helvectica;'>
Please enter your email address in both boxes
<tr>
<td algin='left'>
<font color='white' face='arial'>Email: </font>
<td>
<input type='text' name='email1' value='email1'>
<td align='left'>
<font color='white' face='arial'>Email:</font>
<td>
<input type='text' name='email2' value='email2'>
<tr>
<td align='left' colspan='4'>
<font color='white' face='arial'>Comments:</font>
<tr>
<td colspan='4' align='center'>
<textarea cols='74' rows='8'>
</textarea>
<tr>
<td align='center' colspan='4'>
<input type='submit' value='Send' />
<input type='reset' value='Reset' />
</td>
<tr>
</table>
</span>
</div>";
?>




Reply With Quote