Form Validation formatted in HTML

Novice (Level 1)

Join Date: Mar 2014
Posts: 2
iTrader: (0)
supergia is an unknown quantity at this point

Not Valid results page in HMTL
I was searching your forums for someone who has had this inquiry… but no luck. I was wondering if it is possible to display error results from this code in HMTL instead of plain text. The php code is this:
function died($error) {
// your error code can go here
echo “We’re sorry, but there’s errors found with the form you submitted.

”;
echo $error."

";
echo “Please click your back button and go back to the TacView form and fix these errors.

”;
die();
}

// validation expected data exists
if(!isset($_POST[‘first_name’]) ||
!isset($_POST[‘last_name’]) ||
!isset($_POST[‘email’]) ||
!isset($_POST[‘telephone’]) ||
!isset($_POST[‘comments’])) {
died(‘We are sorry, but there appears to be a problem with the TacView form you submitted.’);
}

$first_name = $_POST[‘first_name’]; // required
$last_name = $_POST[‘last_name’]; // required
$email_from = $_POST[‘email’]; // required
$telephone = $_POST[‘telephone’]; // not required
$comments = $_POST[‘comments’]; // required

$error_message = “”;
$email_exp = ‘/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/’;
if(!preg_match($email_exp,$email_from)) {
$error_message .= ‘The Email Address you entered does not appear to be valid.
’;
}
$string_exp = “/^[A-Za-z .’-]+$/”;
if(!preg_match($string_exp,$first_name)) {
$error_message .= ‘The First Name you entered does not appear to be valid.
’;
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= ‘The Last Name you entered does not appear to be valid.
’;
}
if(strlen($comments) < 2) {
$error_message .= ‘The Comments you entered do not appear to be valid.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;

function clean_string($string) {
$bad = array(“content-type”,“bcc:”,“to:”,“cc:”,“href”);
return str_replace($bad,"",$string);
}

and the error page displayed is this:

We’re sorry, but there’s errors found with the form you submitted.

The Email Address you entered does not appear to be valid.
The First Name you entered does not appear to be valid.
The Last Name you entered does not appear to be valid.
The Comments you entered do not appear to be valid.

Please click your back button and go back to the form and fix these errors.

What I would like to do is have the displayed error page format in html or as pop-up. Can this be done?

Thanks so much.

SuperGia

Just put the html in where the messages are or outside your display of the messages

if(strlen($error_message) > 0) {
echo"YOUR OPENING HTML";
died($error_message);
echo"YOUR CLOSING HTML";
}

Hmm - this does not produce my validation errors in HTML - Just a blank page is produced. Must I include all HTML page code or just the body code? Thanks.

I see what you are saying. I added simple tags and that produced a different result. Thanks. Is there anyway to have this error validation produced as a pop-up or new sized window?

Yes

I understand yes, but how do I make my PHP Form validation results come up as a pop-up or _blank page? Thanks.

Sponsor our Newsletter | Privacy Policy | Terms of Service