Ok I reworked some things including the lower portion using the 'isset' method you suggested as when I enabled error checking it was stopping the form fully loading at these checks, like you implied it would.
As for the first code snippet you posted, I agree I would like to do it a better way though I can't think of a good way to do it to ensure only the right field is called on when an error has occurred in the second section of code.
As for the phone number, its actually for UK phone numbers. I am certainly open to better alternatives though this was the closest one I could come up with and I THINK it should work for any UK landline or mobile number since they apparently are all 11 digits long and start with a 0.
Please let me know what you think.
<html>
<?php
date_default_timezone_set('GMT');
$currentdate=date("D-d");
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
$class1="fields";$class2="fields";$class3="fields";$class4="fields";$class5="fields";$class6="fields";$class7="fields";
//error handler function
function customError($errno, $errstr)
{
echo "<b>Error:</b> [$errno] $errstr<br />";
echo "<b>Error:</b> [$errno] $errstr<br />";
echo "Webmaster has been notified";
error_log("Error: [$errno] $errstr",1,
"supervegetauk2001@yahoo.com","From: webmaster@example.com");
echo "Ending Script";
die();
}
//set error handler
set_error_handler("customError",E_ALL|E_STRICT);
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<body>
<?php
//Check email address is valid
function mailCheck($field)
{
//filter_var() sanitises the e-mail address using FILTER_SANITIZE_EMAIL
$field=filter_Var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
Return TRUE;
}
else
{
Return FALSE;
}
}
function isPhoneNumber($checkNo) {
// validate a phone number
return preg_match("/^([0])[0-9]{10}$/D", $checkNo);
}
//Check that the required fields are filled out - also checks that email, if entered, is valid.
if(isset($_REQUEST['submit']))
{
$fullname=(isset($_REQUEST['fullname']) ? $_REQUEST['fullname'] : NULL);
$fullname=(isset($_REQUEST['email']) ? $_REQUEST['email'] : NULL);
$fullname=(isset($_REQUEST['telno']) ? $_REQUEST['telno'] : NULL);
$fullname=(isset($_REQUEST['mobno']) ? $_REQUEST['mobno'] : NULL);
$fullname=(isset($_REQUEST['incident']) ? $_REQUEST['incident'] : NULL);
$fullname=(isset($_REQUEST['callbackday']) ? $_REQUEST['callbackday'] : NULL);
$fullname=(isset($_REQUEST['callbacktime']) ? $_REQUEST['callbacktime'] : NULL);
//Begin Checks
if(trim($fullname) == '') //Check Name is not empty
{
$errmsg = "<p class='displayerror'>Please enter your name</p>";$class1="errorstyle";
}
else if(trim($telno) == '') //Check Contact Number is not empty
{
$errmsg = "<p class='displayerror'>Please enter a contact number</p>";$class2="errorstyle";
}
else if(!isPhoneNumber($telno)) //If Contact Number has been entered, check it is a valid telephone number
{
$errmsg = "<p class='displayerror'>The number you have entered is invalid. Please try again.</p>";$class2="errorstyle";;
}
else if(trim($incident) == '') //Check that the Incident Type is not empty
{
$errmsg = "<p class='displayerror'>Please indicate the type of incident for which you wish to submit a claim</p>";$class3="errorstyle";
}
else if(trim($callbackday) == '') //CHeck that the Day for Call Back is not empty
{
$errmsg = "<p class='displayerror'>Please select a day for callback</p>";$class4="errorstyle";
}
else if(trim($callbacktime) == '') //Check that the Time for Call Back is not empty
{
$errmsg = "<p class='displayerror'>Please select a call back time</p>";$class5="errorstyle";
}
else if(!empty($email) || !empty($mobno)) //Check whether the user has entered an e-mail address or mobile number (Optional data)
{
if (!empty($email) && !mailCheck($email)) //If an Email has been entered but it is not valid
{
$errmsg = "<p class='displayerror'>E-mail is invalid</p>";$class6="errorstyle";
}
else if (!empty($mobno) && !isPhoneNumber($mobno)) //If a mobile number has been entered but it is not valid
{
$errmsg = "<p class='displayerror'>The mobile number you entered is invalid. Please try again.</p>";$class7="errorstyle";
}
else //Otherwise, make sure it can escape the loop and process the e-mail
{
$notEmpty='1';
}
}
else //If none of the above is true, make sure the e-mail loop can be activated
{
$notEmpty='1';
}
}
//If all necessary fields are filled out, begin validating the data and submit the claim
if(!empty($fullname) && !empty($telno) && !empty($incident) && !empty($callbackday) && !empty($callbacktime) && !empty($notEmpty))
{
//message contents
//personal details
$title = $_REQUEST['title'];
$dobd=$_REQUEST['dobd'];
$dobm=$_REQUEST['dobm'];
$doby=$_REQUEST['doby'];
//incident details
$incidentdate = $_REQUEST['incidentdate'];
$details = $_REQUEST['details'];
//The Actual Email. All the components are here to send an email with the message in full.
$destination_email = "supervegetauk2001@yahoo.com";
$subject = "NEW CLAIM: " . $incident . " - Made On " . ($currentdate);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: claim@cash4aclaim.com' . "\r\n";
//The actual contents of the message, formatted in HTML for easy reading.
$message='<html>
<head>
<title>Claim Form Submitted</title>
</head>
<body>
<h1><u>cash4aCLAIM.com Claim Form</u></h1>
New Claim Request made on ' . ($currentdate) . ' by ' . ($title) . ' ' . ($fullname) .
'<h2>Claimant Information</h2>
<table border=1 cellpadding=3 >
<tr>
<td><b>Claimant:</b> </td> <td>' . ($title) . ' ' . ($fullname) . '</td>
</tr>
<tr>
<td><b>Date of Birth:</b> </td> <td>' . ($dobd).'-'.($dobm).'-'.($doby).'</td>
</tr>
<tr>
<td><b>Email:</b> </td> <td>' . ($email) . '</td>
</tr>
<tr>
<td><b>Contact Number:</b> </td> <td>' . ($telno) . '</td>
</tr>
<tr>
<td><b>Mobile Number:</b> </td> <td>' . ($mobno) . '</td>
</tr>
</table>
<h2>Incident Information</h2>
<table border=1 cellpadding=3 >
<tr>
<td><b>Incident Type:</b> </td> <td>' . ($incident) . '</td>
</tr>
<tr>
<td><b>Incident Date:</b> </td> <td>' . ($incidentdate) . '</td>
</tr>
<tr>
<td><b>Incident Details:</b> </td> <td>' . ($details) . '</td>
</tr>
</table>
<h2>Callback Info</h2>
<table border=1 cellpadding=3 >
<tr>
<td><b>Callback Day:</b> </td> <td>' . ($callbackday) . '</td>
</tr>
<tr>
<td><b>Callback Time:</b> </td> <td>' . ($callbacktime) . '</td>
</tr>
</table>
</body>
</html>';
if(mail($destination_email, $subject,$message,$headers))
{
echo "<h2>Your claim has been successfully submitted. We should be contacting you soon!</h2>";
}
else
{
echo "<h2>An error has occured, the webmaster has been notified.</h2> <br/>
We apologise for any inconvenience.".
mail("majinvegeta90@hotmail.com","Error has occured in mail system","Error in claim system",$headers);
}
}