Hi,
I am very new to PHP, and am only about three weeks or so into actually learning it. I have constructed a form and it does all work except for two things which hopefully some of you may be able to assist me with.
1) First, I am try to validate an email address. I have searched the internet, and found the code in which to do it, but I am having issues actually implementing it. I was hoping some of you may be able to assist me and take a look at my code below to see where I am going wrong.
2) When an error occurs in the form, the user is sent to the formhandler.php which provides them with the errors, however, since my page is a one page portfolio they are redirected to the top of the page, but my form is at the bottom. I used the <meta http-equiv="refresh" content="0; url=index.html"/> code, and it produces the results I want to a certain extent. The problem is, if you try to reload the page, it is sent into a loop of death in which the page continously refreshes itself. I am trying to use the header option but obviously this not working because its in the formhandler.php. I tried the ob_start but could not get it to work either.
Hopefully someone will be able to shed some light on my dilemmas. Here is the code I am dealing with (I have pasted the entire php section to ensure I didn't leave any small detail out):
php:
<?php
$name = $POST['realname'] ;
$email = $POST['email'] ;
$message = $_POST['message'] ;
$errorFlag = false;
$errorEmail = false;
$errorName = false;
$errorMessage = false;
if (!$name) {$errorFlag = true; $errorName = true;}
if (!$email) {$errorFlag = true; $errorEmail = true;}
if (!$message) {$errorFlag = true; $errorMessage = true;}
if ($errorFlag == true) {
?>
<div id="errorColumn">
<h4><img src="images/alert.gif" alt="Alert" title="Alert" class="alert"/>An error has occured:</h4>
<ul class="ulerror">
<?php header( "Location: formhandler.php#contactnav" ); ?>
<?php if ($errorName == true) {echo "<li>The following fields are required: Name</li>";} ?>
<?php if (eregi("[a-z0-9-]+(.[a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email)) {
echo "<li>The following fields are required: Valid Email</li>";} ?>
<?php if ($errorEmail == true) {echo "<li>The following fields are required: Email</li>";} ?>
<?php if ($errorMessage == true) {echo "<li>The following fields are required: Message</li>";} ?>
</ul>
</div>
<?php } else { header( "Location: formhandler.php#contactnav" ); ?>
<?php mail( "blank@gmail.com", "Design Form Submission", $message, "From: $name $email" );
?>
<div id="approvedColumn">
<h4><img src="images/success.gif" alt="Success" title="Success" class="alert"/>Submission successful!</h4>
<p class="lastpara">Thank you for your form submission. Sit back and relax, your inquiry will be looked into shortly.</p>
</div>
<?php } ?>
Thanks,
James