Hi,
I have created a contact form for my site using PHP, which checks the inputs to a form and then sends a mail to a selected address. The process works fine and I get the mail with no issues.
What I am struggling with is the display of the results
The form is online at Here
The results are displayed, but underneath an empty form. If there are any errors the user has to use the browser back button to see the form with the data they entered so that they can make changes.
What I would like to do is display the results without the empty form.
Here is my coding
<?php $myemail = 'xxxxxxxxxx';$subject = 'Contact from English Electric Growl';
$op = $_POST[op];if($op == 'contact'){
$name = stripslashes($_POST[name]);
$email = stripslashes($_POST[email]);
$topic = stripslashes($_POST[topic]);
$text = stripslashes($_POST[text]);
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email))
{$status = "We're sorry, but you've entered an incorrect email address.<br>";
}if(
!$name){$status .= "Please enter your name.<br>";
}if(
!$topic){$status .= "Please select a Topic.<br>";
}if(
!$text){$status .= "Please enter a message.<br>";
}if(!$status){
$header = "From: $email\r\nReply-To: $email\r\n";
$message = "Name: $name\n\nEmail: $email\n\nTopic: $topic\n\nMessage:\n$text";
if(mail($myemail, $subject, $message, $header)){$status = "Thank you for contacting us!!<br><br>";
}else{
$status = "There was a problem sending your contact form, please try again later.<br><br>";}
}else{
$status .= "<br>Please press back on your browser to resubmit.<br><br>";}}
$referer = $_SERVER[HTTP_REFERER];
if(!preg_match('#^http\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $referer)){unset($referer);}?>
<form method="post" action="<?php print $_SELF; ?>" id="insertForm">
<input type="hidden" name="op" value="contact" />
<table cellpadding="0" cellspacing="0" id="insertTable">
<caption>Contact Form</caption>
<tr><th width="100">
Name</th>
<td>
<input name="name" size="35" value="" /></td></tr>
<tr><th>E-mail address</th>
<td>
<input name="email" size="35" value="" /></td></tr>
<tr>
<th><label for="topic">Topic</label></th>
<td>
<select name="topic" id="topic">
<option value="">Please select from the drop down list</option>
<option value="Contribution">Contribution</option>
<option value="Request">Request</option>
<option value="Photograph">Photograph</option>
<option value="Recommend">Recommendations</option>
<option value="Link Exchange">Link Exchange</option>
<option value="Spares">Spares</option>
<option value="Other">Other</option></select>
</td>
</tr>
<tr><th>Message</th>
<td>
<textarea name="text" cols="50" rows="10"></textarea></td></tr>
<tr><th>Security</th>
<td>CAPTCHA info</td>
</tr>
<tr><th></th>
<td>
<input type="submit" id="button" value="Send Message" /></td></tr></table>
</form><br /><?php print $status; ?>
I hope someone might be able to help me
Regards
Phil