I ended up going with this, is a multi-page form so I store the errors message in a session and redirect them back to the page.
if ($_POST['cartId'] == $_POST['vcartId']) {
$_SESSION['cartId']=$_POST['cartId'];
} else {
$error_msg .= "Sorry, the phone numbers did not match, please try again" . "<br />";
}
if (($_POST['cartId'] == $_POST['vcartId']) && (is_numeric($_POST['cartId'])) ){
$_SESSION['cartId']=$_POST['cartId'];
} else {
$error_msg .= "Sorry, your phone number must be all numerical characters<br />No \"-\" or \"()\" allowed, please try again " . "<br />";
}
if (($_POST['cartId'] == $_POST['vcartId']) && (strlen($_POST['cartId']) >= 9) ){
$_SESSION['cartId']=$_POST['cartId'];
} else {
$error_msg .= "Sorry, the phone number entered is not valid, please try again" . "<br />";
}
This runs my error message
//Sends user back if required not filled
if ( !empty($error_msg) ){
$_SESSION['error_prn']=$error_msg;
header("Location: mobile.php");
}
and this displays on page if error_msg is in session
<?php
if ( isset($_SESSION['error_prn']) && $_SESSION['error_prn'] )
{
echo "<pre class=\"alert\">{$_SESSION['error_prn']}</pre>";
}
?>
Works good. My only issue is when a user successfuly passes after erroring out the first time, the error message is still in session so if they don't complete the form and come back before the session expires they will see the error message again.