1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
<?php
function heading()
{
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Number Sum</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
';
}
function footer()
{
echo '</body></html>';
}
function form1()
{
echo '
<h3>Give me a number</h3>
<form action="numbersum.php" method="post">
<div>
<input name="firstNum" type="text"/>
<input name="submit" type="submit"/>
</div>
</form>
';
}
function form2($firstNum)
{
echo '
<h3>Give me another number</h3>
<form action="numbersum.php" method="post">
<div>
<input name="secondNum" type="text"/>
<input name="firstNum" value="',$firstNum,'" type="hidden">
<input name="submit" type="submit"/>
</div>
</form>
';
}
function result($firstNum, $secondNum)
{
echo '<h3>The sum is ', ($firstNum + $secondNum), '</h3>
<form action="numbersum.php" method="post">
<div>
<input name="submit" type="submit">
</div>
</form>
';
}
heading();
if (isset($_POST["secondNum"])) {
result($_POST["firstNum"], $_POST["secondNum"]);
} else {
if (isset($_POST["firstNum"])) {
form2($_POST["firstNum"]);
} else {
form1();
}
}
footer();
?> |
Partager