I'm sure this is simple but the answer eludes me.
I have a form that the customer fills out, which is then validated if there is an error they are directed to correct the information. Both the main entry page and the validation page are loaded dynamically (i.e. <a href="index.php?page=myform"> and action="index.php?page=valform"). The validation form checks the information and if there is an error the form then "includes" the original form with customers entered data and indicates what information is incorrect. But if the information is correct I would like to have the information load into a new page that is "printer friendly".
I don't think the code is needed but here it is any way
<?php
function isDigits($element) {
return !preg_match ("/[^0-9]/", $element);
}
function isLetters($element) {
return !preg_match ("/[^A-z]/", $element);
}
function checkLength($string, $min, $max) {
$length = strlen ($string);
if (($length < $min) || ($length > $max)) {
return FALSE;
} else {
return TRUE;
}
}
function checkPhone($code){
$code = preg_replace("/[\s|-]/", "", $code);
$length = strlen ($code);
if (($length <> 10) && ($length <> 11)) {
return FALSE;
}
return isDigits($code);
}
$valid = TRUE;
if (isset ($_POST['submit'])) {
foreach($_POST as $key=>$value) {
$$key = $value;
}
$valid = $fn = checkLength($fname, 1, 30);
$ln = checkLength($lname, 1, 30);
$valid = $valid && $ln;
$pn = checkPhone($phone);
$valid = $valid && $pn;
$st = checkLength($street1, 7, 50);
$valid = $valid && $st;
$cty = checkLength($city, 5, 50);
$valid = $valid && $cty;
$sp = checkLength($state, 2, 50);
$valid = $valid && $sp;
$ac = checkLength($country, 2, 50);
$valid = $valid && $ac;
$zp = checkLength($zipcode, 5, 50);
$valid = $valid && $zp;
$msg = checkLength($notes, 5, 500);
$valid = $valid && $msg;
if ($valid)
{
//have a new page load with the forms contents that is "printer friendly"
}
}
else
{
$fn = $ln = $pn = $st = $cty = $sp = $ac = $zp = $msg = TRUE;
$fname = $lname = $street1 = $street2 = $city = $state = $country = $zipcode = $notes = '';
}
if (!$valid)
{
//include the form with all errors indicated
}
?>