function validate() { global $productId; global $rateplanId; global $chargeIds; global $requireFieldsArray; if (isEmpty($productId)) { return false; } if (isEmpty($rateplanId)) { return false; } if (!isset($chargeIds)) { return false; } $valid = true; foreach ($requireFieldsArray as $ea) { $valid = $valid && validateValue($ea); } return $valid; }
function validate() { global $productId; global $rateplanId; global $chargeIds; global $requireFieldsArray; global $ValidationStatus; global $gCreditCardNumber; global $gStartDate; global $gValidated; // $fieldsValue[$address1], '', $fieldsValue[$city], $fieldsValue[$state], 'USA', $fieldsValue[$postalCode] if (isEmpty($productId)) { return false; } if (isEmpty($rateplanId)) { return false; } if (isEmpty($_POST['Docs'])) { $ValidationStatus = "Please select a Doctor"; return false; } if (isEmpty($_POST['CCInfo'])) { $ValidationStatus = "Please enter a cc number"; return false; } // CreditCardNumber // if(!isset($chargeIds)) return false; if (isset($chargeIds)) { if (empty($_POST['Charges'])) { //if (sizeof ( $chargeIds ) < 1) { $ValidationStatus = "Please select a value in the charge list"; return false; } else { //$ValidationStatus = ""; } } else { $ValidationStatus = "Please select a value in the charge list"; return false; } // if(sizeof($chargeIds)>1) return false; // Now update the cc info global $gAddress1; global $gCity; global $gState; global $gPostalCode; global $gFirstName; global $gLastName; global $gFullName; global $gCreditCardExpirationMonth; global $gCreditCardExpirationYear; global $gCreditCardNumber; global $fieldsValue; global $Name; //Set the global address vars //$fieldsValue["Address1"]=$_POST["Address1"]; //$gCity=$fieldsValue["City"]; //$gState=$fieldsValue["State"]; //$gPostalCode =$fieldsValue["PostalCode"]; if (!isEmpty($fieldsValue["CCInfo"])) { $ParsedString = explode("^", $fieldsValue["CCInfo"]); $ParsedName = explode("/", $ParsedString[1]); $gCreditCardNumber = substr($ParsedString[0], 2, strlen($ParsedString[0]) - 2); $gFirstName = substr($ParsedString[1], stripos($ParsedString[1], "/") + 1, 99); $gLastName = $ParsedName[0]; if ($gValidated != 'YES') { $gFullName = trim($gLastName) . ", " . trim($gFirstName) . " - Wellbeing"; } else { $gFullName = $_POST['Name']; } $Name = trim($gFirstName) . " " . trim($gLastName); //$gFullName; $gCreditCardExpirationMonth = substr($ParsedString[2], 2, 2); $gCreditCardExpirationYear = "20" . substr($ParsedString[2], 0, 2); } // end update cc info if (!isEmpty($fieldsValue["StartDate"])) { $StartDate = $_POST['StartDate']; } else { $gStartDate = date("m/d/Y"); } //Check required field if (!isEmpty($fieldsValue["CreditCardNumber"])) { $valid = true; foreach ($requireFieldsArray as $ea) { $valid = $valid && validateValue($ea); } } $gValidated = 'YES'; return $valid; //true; }
function checkVar($target, $untrusted_value, $awaited_type, $min, $max, $default_value, $label, $array_return, $die_on_fail) { $value_accepted = true; $error = ""; // 1. filter value according to target (web page or database) // converts to correct charset, removes unwanted values, encodes special chars // does nothing if not $target = "" $untrusted_value = filterValue($target, $untrusted_value); // 2. checks var content against awaited type if ($awaited_type != "") { $value_accepted = validateType($target, $untrusted_value, $awaited_type); if ($value_accepted == 0) { $error .= "bad type, " . $awaited_type . " awaited."; } } else { // sets var type if not specified, for next check against bounds if (is_numeric($untrusted_value)) { $awaited_type = "float"; } else { $awaited_type = "string"; } } // 3. checks var content against bounds if ($value_accepted) { // numeric : checks var content against values bounds if ($awaited_type == "int" || $awaited_type == "float" || $awaited_type == "hex") { echo $awaited_type . "<br>"; $value_accepted = validateValue($untrusted_value, $min, $max); if (!$value_accepted) { $error .= "bad value, " . $min . " to " . $max . " expected."; } } // string : checks var content against length bounds if ($awaited_type == "string" || $awaited_type == "date" || $awaited_type == "url" || $awaited_type == "email") { $value_accepted = validateLength($untrusted_value, $min, $max); if (!$value_accepted) { $error .= "bad length, " . $min . " to " . $max . " chars expected."; } } } if ($value_accepted) { switch ($array_return) { case 0: // returns a single value without feedback return $untrusted_value; break; case 1: // returns an array with filtered value or default value with error feedback if validation fails (useful for form validation) return array("ok" => true, "value" => $untrusted_value, "error" => ""); } } else { if ($die_on_fail) { exit("Fatal error :: bad var value detected"); if ($debug_mode == "on") { echo "<br>'" . $label . "' " . $error; } } switch ($array_return) { case 0: // returns a single value without feedback return $default_value; break; case 1: // returns an array with filtered value or default value with error feedback if validation fails (useful for form validation) return array("ok" => false, "value" => $default_value, "error" => "'" . $label . "' " . $error); } } }