示例#1
0
/**
 * validates the order form and calls the displayAddonsForm method
 * @param $post array $_POST
 * @param $items array of item objects
 * @param $toppings array of topping objects
 * @param $order Order class object
 */
function validateForm($post, $items, $toppings, $order)
{
    /*validation varibles are used and modified by the the data on the $post array 
     * in order to be used by the conditions below and validate input*/
    $validInts = sizeof($post);
    $numItems = 0;
    $stringFound = false;
    $negativeInt = false;
    $quantityLessThanTen = true;
    //string to be use for error handleling
    $error = ' ';
    /*loops through the $post array to assign the right value 
     *to the validation variables*/
    foreach ($post as $item => $value) {
        //condition that ensures validation of only input boxes
        if ($items["{$item}"]) {
            $numItems += $value;
            if ($value == "") {
                $validInts--;
            }
            if (validateInt($value) === false && $value !== '' && $value !== ' ') {
                $stringFound = true;
            }
            if ($value < 0) {
                $negativeInt = true;
            }
            if ($value > 10) {
                $quantityLessThanTen = false;
            }
        }
    }
    /*use the above defined variables to validate "all"(or so I like to think) 
      possible scenarios of the user's input*/
    if ($stringFound === true) {
        $error = '
        Invalid quantity found, 
        please enter positive whole numbers.';
        $order->displayOrderForm($error, $items);
    } elseif ($negativeInt === true) {
        $error = 'Enter positive whole numbers only.';
        $order->displayOrderForm($error, $items);
    } elseif ($validInts === 0 || $numItems === 0) {
        $error = 'Please enter a quantity for the items you want.';
        $order->displayOrderForm($error, $items);
    } elseif ($quantityLessThanTen === false) {
        $error = 'I am sorry, you can only order 10 or less of each item.
        Contact our catering deparment at ITC250 P2 Team 3';
        $order->displayOrderForm($error, $items);
    } elseif ($validInts > 0 && $numItems > 0) {
        $order->saveOrder($post);
        $order->displayAddOnsForm($items, $toppings);
    } else {
        $error = 'Unknow error; please try again...';
        $order->displayOrderForm($error, $items);
    }
}
示例#2
0
<?php

require_once "includes/setup.php";
if ($isLogedIn) {
    $user = $_SESSION['user'];
}
$page = setPage($_GET['page']);
$num_per_page = 12;
if (isset($_GET["addid"])) {
    if (!$isLogedIn) {
        header("Location: store.php");
    }
    if ($_GET['token'] == $_SESSION['token']) {
        $productId = sanitize($_GET["addid"]);
        if (validateInt((int) $productId)) {
            $db->addProductToCart($user->getUserName(), $productId);
            header("Location: store.php?page={$page}");
        }
    }
}
$token = md5(uniqid(rand(), TRUE));
$_SESSION['token'] = $token;
require_once "includes/header.php";
?>

			
					
			<div id="menu_wrapper">
				<div id="menu_container">
					<!--<div id="menu_object_container">-->
						<a href="index.php" class="menu_object">
示例#3
0
function setPage($input)
{
    if (!empty($input)) {
        $page_u = sanitize($input);
        if (validateInt((int) $page_u)) {
            return $page_u;
        }
    }
    return 1;
}