Untitled
unknown
plain_text
4 years ago
1.1 kB
11
Indexable
<?php
require_once 'WiseMan.php';
// list of valid categories; more categories may be added in the future!
$categories = [ 'love', 'life', 'friend'];
// 1. initialize variables
$quote = '';
// first category is set as 'love'
$category = $categories[0];
// 2. process
if(isset($_POST['category'])){
$category = $_POST['category'];
$wiseman = new WiseMan($category);
$quote = $wiseman->getQuote();
}
// 3. display
?>
<html>
<body>
<form method="post">
Category:
<?php
foreach ($categories as $item) {
$checked = '';
if($item == $category) {
$checked = 'checked';
}
echo "
<input type='radio' name='category' id='category_'$item' value='$item' $checked/>
<label for='category_'$item'> $item </label>
";
}
?>
<input type='submit' value='Get quote' />
</form>
<h1> <?=$quote ?> </h1>
</body>
</html>Editor is loading...