<?php
include('includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
echo('<h1>Mad Libs</h1>');
echo('<h2>Insert your words for the Mad Lib</h2>');
// Note the variables being passed via the GET ternary operators.
$step = isset($_GET['step']) ? $_GET['step'] : 0;
$adjective = isset($_GET['adjective']) ? $_GET['adjective'] : '';
$food = isset($_GET['food']) ? $_GET['food'] : '';
$verb = isset($_GET['verb']) ? $_GET['verb'] : '';
$verb2 = isset($_GET['verb2']) ? $_GET['verb2'] : '';
$adjective2 = isset($_GET['adjective2']) ? $_GET['adjective2'] : '';
$noun2 = isset($_GET['noun2']) ? $_GET['noun2'] : '';
// filter all input taken from the Browser
$step = htmlentities($step);
$adjective = htmlentities($adjective);
$food = htmlentities($food);
$verb = htmlentities($verb);
$verb2 = htmlentities($verb2);
$adjective2 = htmlentities($adjective2);
$noun2 = htmlentities($noun2);
if ($step == 0) // first time into this form
{
?>
<form action="madlibs.php" method="GET" class="pad">
<label for="adjective">Adjective</label>
<input type="text" size="36" id="adjective" name="adjective" value="">
<br><br>
<label for="food">Type of food</label>
<input type="text" size="36" id="food" name="food" value="">
<br><br>
<label for="verb">Verb ending in -ing</label>
<input type="text" size="36" id="verb" name="verb" value="">
<br><br>
<label for="verb2">Verb2</label>
<input type="text" size="36" id="verb2" name="verb2" value="">
<br><br>
<label for="adjective2">Adjective2</label>
<input type="text" size="36" id="adjective2" name="adjective2" value="">
<br><br>
<label for="noun2">Noun2</label>
<input type="text" size="36" id="noun2" name="noun2" value="">
<br><br>
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit">
</form>
<?php
} else // creates different strings for to use in the story
{
$inputs = $adjective . $food . $verb . $verb2 . $adjective2 . $noun2;
$count = strlen($inputs);
$capitalizeVerb = ucfirst($verb);
$story = "It was a $adjective day in February. Today was a special day because I could smell the
$food from upstairs. $capitalizeVerb downstairs I see my parents preparing the unique meal. 'Go play outside,
$food will be ready soon,' my mom says. 'Don't forget to $verb2 before you come in.' Outside I
come across a $adjective2 $noun2. It was the most intriguing discovery of my life!";
echo($story);
echo('<p>Your inputs string length is: ' . $count . '</p>');
}
// provide a form to try again
if (!$step == 0){
?>
<form action="madlibs.php" method="GET">
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Try Again">
</form>
<?php
}
include('includes/footer.php');
?>