Hi There,
I am using the following code to validate certain fields on a form,
Currently, the form is posting to itself, and then the script below is run, but once these checks are performed I need to send the $_POST arrays to another page,
I dont know how to do this, can anyone help, or point me in the right direction,
<?
if (isset($_POST['Submit'])) {
$error_msg='';
if(trim($_POST['name'])=='' || strlen(trim($_POST['name'])) < 3) {
$error_msg.="<b>ERROR-1:</b> First name should contain between 3 and 12 alpha charecters<br>Please correct this and re-submit the form<br><br>";
}
if(trim($_POST['sname'])=='' || strlen(trim($_POST['sname'])) < 3) {
$error_msg.="<b>ERROR-2:</b> Last name should contain between 3 and 12 alpha charecters<br>Please correct this and re-submit the form<br><br>";
}
// check if email address have been included / if not lsts error
if(trim($_POST['email'])=='') {
$error_msg.="<b>ERROR-3:</b> Please enter an email<br>Email address are allways lower case.<br>Please correct this and re-submit the form<br><br>";
} else {
// check if email is a valid address in this format user@domain.com.net.co.uk.biz.cs.biz
if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $_POST['email'])) $error_msg.="<b>ERROR-4:</b> Please enter a valid email address<br>Email address should be in user@domain.com OR any valid format<br>Please correct this and re-submit the form<br><br>";
}
// Now check that all the characters are digits
if (!ereg('^[0-9]{10,20}$',$_POST['phonen'])) {
$error_msg.="<b>ERROR-5:</b> Telephone numbers contain 10 / 20 digits<br>Please enter your phone number with Country & OR STD code<br>Please correct this and re-submit the form<br><br>";
}
if(empty($_POST['topic'])){
$error_msg.="<b>ERROR-6:</b> Please enter a topic and submit the form";
}
}
?>
I want the form to validate inside itself, then once passed to send the post vars/arrays to another page
many thanks for reading
lozza