Old fortune cookie generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

77 lines
2.7 KiB

<!-- Holly McFarland - 000778232 -->
<!-- 2019-09-23 -->
<!-- The input page for the fortune cookie generator -->
<?php
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
if ($name === null) { $name = ''; }
$num = filter_input(INPUT_POST, 'num', FILTER_VALIDATE_INT);
if ($num === null || $num === false) { $num = '1'; }
$colour = filter_input(INPUT_POST, 'colour', FILTER_SANITIZE_STRING);
if ($colour === null || $colour === false) { $colour = '#ffda5c'; }
$min = filter_input(INPUT_POST, 'min', FILTER_VALIDATE_INT);
if ($min === null || $min === false) { $min = '1'; }
$max = filter_input(INPUT_POST, 'max', FILTER_VALIDATE_INT);
if ($max === null || $max === false) { $max = '20'; }
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Fortune Cookie Generator</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
function updateMaxValidation() {
let min = document.forms.cookieoptions.min;
let max = document.forms.cookieoptions.max;
max.setAttribute("min", parseInt(min.value) + 6);
max.setCustomValidity("");
}
function maxInvalid() {
let max = document.forms.cookieoptions.max;
if (parseInt(max.value) > 99) {
max.setCustomValidity("Please select a value that is no more than 99.");
} else {
max.setCustomValidity("Please select a value that is at least 6 more than min.");
}
}
function resetMax() {
this.setCustomValidity("");
}
window.onload = function() {
document.forms.cookieoptions.min.addEventListener("input", updateMaxValidation);
document.forms.cookieoptions.max.addEventListener("input", resetMax);
document.forms.cookieoptions.max.addEventListener("invalid", maxInvalid);
updateMaxValidation();
}
</script>
</head>
<body>
<h1>Fortune Cookie Generator</h1>
<form action="cookies.php" method="post" id="cookieoptions">
<label for="name">What is your name?</label>
<input type="text" name="name" placeholder="Optional" value="<?php echo $name; ?>">
<br>
<label for="name">How many cookies would you like?</label>
<input type="number" name="num" min="1" max="100" value="<?php echo $num; ?>" required>
<br>
<label for="colour">What colour should the cookies be?</label>
<input type="color" name="colour" value="<?php echo $colour; ?>" required>
<br>
<label for="min">Enter minimum and maximum lucky numbers:</label>
<input id="min" type="number" name="min" placeholder="Min" min="1" max="93" value="<?php echo $min; ?>" required>
<input id="max" type="number" name="max" placeholder="Max" min="7" max="99" value="<?php echo $max; ?>" required>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>