Esempio n. 1
0
function validateSecondForm(&$errors)
{
    global $month, $day, $year, $user_format;
    if (!validateRequired($month)) {
        $errors['month'][] = 'Please enter a month.';
    } else {
        if (!validateNumeric($month)) {
            $errors['month'][] = 'This must be a number!';
        }
    }
    if (!validateRequired($day)) {
        $errors['day'][] = 'Please enter a day.';
    } else {
        if (!validateNumeric($day)) {
            $errors['day'][] = 'This must be a number!';
        }
    }
    if (!validateRequired($year)) {
        $errors['year'][] = 'Please enter a year.';
    } else {
        if (!validateNumeric($year)) {
            $errors['year'][] = 'This must be a number!';
        }
    }
    if (!validateRequired($user_format)) {
        $errors['user_format'][] = 'Please enter the format!';
    }
    return empty($errors);
}
Esempio n. 2
0
function validateForm(&$errors)
{
    global $temperature, $conversion;
    if (!validateRequired($temperature)) {
        $errors['temperature'][] = 'Please enter the temperature.';
    } else {
        if (!validateNumeric($temperature)) {
            $errors['temperature'][] = 'This must be a number!';
        }
    }
    return empty($errors);
}
Esempio n. 3
0
function validateForm(&$errors)
{
    global $firstNumber, $secondNumber, $operation;
    if (!validateRequired($firstNumber)) {
        $errors['firstNumber'][] = 'Please enter a number.';
    } else {
        if (!validateNumeric($firstNumber)) {
            $errors['firstNumber'][] = 'This must be a number!';
        }
    }
    if (!validateRequired($secondNumber)) {
        $errors['secondNumber'][] = 'Please enter a number.';
    } else {
        if (!validateNumeric($secondNumber)) {
            $errors['secondNumber'][] = 'This must be a number!';
        }
    }
    return empty($errors);
}
<?php

DEFINE('INCLUDE_CHECK', 1);
require_once 'lib/connections/db.php';
include 'lib/functions/functions.php';
checkLogin('2');
// we check if everything is filled in and perform checks
if ($_POST['phone'] && !validateNumeric($_POST['phone'])) {
    die(msg(0, "Phone numbers must be of numeric type only."));
}
if ($_POST['email'] && validateEmail($_POST['email'])) {
    die(msg(0, "Invalid Email!"));
}
if ($_POST['email'] && uniqueEmail($_POST['email'])) {
    die(msg(0, "Email already in database. Please select another email address."));
}
$res = editUser($_SESSION['user_id'], $_POST['email'], $_POST['first_name'], $_POST['last_name'], $_POST['dialing_code'], $_POST['phone'], $_POST['city'], $_POST['country']);
if ($res == 4) {
    die(msg(0, "An internal error has occured. Please contact the site admin!"));
}
if ($res == 99) {
    die(msg(1, "Profile updated successfully!"));
}
function msg($status, $txt)
{
    return '{"status":' . $status . ',"txt":"' . $txt . '"}';
}
Esempio n. 5
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 "";
}