コード例 #1
0
function validate()
{
    if (!validateAlpha($_POST['fname'])) {
        echo '<script type="text/javascript">alert("Not a valid firstname!")</script>';
        return false;
    }
    if (!validateAlpha($_POST['lname'])) {
        echo '<script type="text/javascript">alert("Not a valid lastname!")</script>';
        return false;
    }
    if (!validateAlphaNumeric($_POST['address'])) {
        echo '<script type="text/javascript">alert("Not a valid address!")</script>';
        return false;
    }
    if (!validatePhone($_POST['phone'])) {
        echo '<script type="text/javascript">alert("Not a valid phone number, use ###-###-####!")</script>';
        return false;
    }
    if (!validateEmail($_POST['email'])) {
        echo '<script type="text/javascript">alert("Not a valid email!")</script>';
        return false;
    }
    return true;
}
コード例 #2
0
function ProcessItem($formid, $fvalue, $params, $output_type)
{
    global $TOOL_SHORT;
    $PASS_VALUE = "ok";
    $FAIL_VALUE = "error";
    global $VALIDATE_TEXT;
    $failed = false;
    $VALIDATE_TEXT = "";
    // clear before doing the validation
    if (!validateRequired($fvalue) && !array_key_exists("required", $params)) {
        // blank and not required
        return "";
    }
    // do the validation
    foreach ($params as $value) {
        if ($failed) {
            break;
        }
        $type = $value;
        if (strpos($value, ";") !== false) {
            // get the special rule type
            $type = substr($value, 0, strpos($value, ";"));
        }
        writeLog($TOOL_SHORT, "ajax", "validate:" . $type . ":" . $fvalue);
        if ($type == "required" || $type == "notblank") {
            if (!validateRequired($fvalue)) {
                $failed = true;
            }
        } else {
            if ($type == "email") {
                if (!validateEmail($fvalue)) {
                    $failed = true;
                }
            } else {
                if ($type == "phone") {
                    if (!validatePhone($fvalue)) {
                        $failed = true;
                    }
                } else {
                    if ($type == "date") {
                        if (!validateDate($fvalue)) {
                            $failed = true;
                        }
                    } else {
                        if ($type == "time") {
                            if (!validateTime($fvalue)) {
                                $failed = true;
                            }
                        } else {
                            if ($type == "zip" || $type == "zipcode") {
                                if (!validateZip($fvalue)) {
                                    $failed = true;
                                }
                            } else {
                                if ($type == "nospaces" || $type == "password") {
                                    if (!validateNoSpaces($fvalue)) {
                                        $failed = true;
                                    }
                                } else {
                                    if ($type == "alpha") {
                                        if (!validateAlpha($fvalue)) {
                                            $failed = true;
                                        }
                                    } else {
                                        if ($type == "alphanum") {
                                            if (!validateAlphaNumeric($fvalue)) {
                                                $failed = true;
                                            }
                                        } else {
                                            if ($type == "number") {
                                                if (!validateNumeric($fvalue)) {
                                                    $failed = true;
                                                }
                                            } else {
                                                if ($type == "name") {
                                                    if (!validateAlphaName($fvalue)) {
                                                        $failed = true;
                                                    }
                                                } else {
                                                    if ($type == "namespaces") {
                                                        if (!validateAlphaNameSpaces($fvalue)) {
                                                            $failed = true;
                                                        }
                                                    } else {
                                                        if ($type == "uniquesql") {
                                                            // should be uniquesql;(columnname);(tablename);(tableid);(userid)
                                                            $parts = split(';', $value);
                                                            if (!validateUniqueSQL($parts[1], $parts[2], $fvalue, $parts[3], $parts[4])) {
                                                                $VALIDATE_TEXT = $formid . " already used";
                                                                $failed = true;
                                                            }
                                                        } else {
                                                            if ($type == "uniqueinstp") {
                                                                // should be uniqueinstp;(value);($field);(idval)
                                                                $parts = split(';', $value);
                                                                if (!validateUniqueInst($fvalue, $parts[1], $parts[2])) {
                                                                    $VALIDATE_TEXT = $formid . " already used";
                                                                    $failed = true;
                                                                }
                                                            } else {
                                                                if ($type == "uniqueuserp") {
                                                                    // should be uniqueuserp;(value);($field);(idval)
                                                                    $parts = split(';', $value);
                                                                    if (!validateUniqueUser($fvalue, $parts[1], $parts[2])) {
                                                                        $VALIDATE_TEXT = $formid . " already used";
                                                                        $failed = true;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($output_type == "ajax") {
        $status = $PASS_VALUE;
        if ($failed) {
            $status = $FAIL_VALUE;
        }
        $ajaxReturn = "{$status}|{$formid}|{$VALIDATE_TEXT}";
        echo $ajaxReturn;
        writeLog($TOOL_SHORT, "ajax", "return={$ajaxReturn}");
    } else {
        if ($output_type == "print") {
            if ($failed) {
                print $VALIDATE_TEXT . "<br>";
            }
        } else {
            if ($output_type == "array") {
                if ($failed) {
                    return $VALIDATE_TEXT;
                }
            }
        }
    }
    // defaults to "return"
    if ($failed) {
        return $VALIDATE_TEXT . "<br>";
    }
    return "";
}