$data = $_GET["textbox"]; if ($data) seenWordsView(explode(" ", $data)); else formView($data);}
# Display form ?>Enter your message here: <form method="get" action="message.php"> <input type="text" name="textbox" size="10" /> <input type="submit" name="sendform" value="Don't Panic!" /> </form><?php}
# Heading ?><h1>Words Seen</h1><?php
foreach ($data as $word) echo "<div>$word</div>";
echo "}
<a href=\"message.php?\">Back</a>";
* Dennis Hsu * form exercise for CS 174 */
* Controls which view to show based on if data has been entered or not */function messageController() {
$data=$_GET; if ($data) { seenWordsView($data); } else { formView($data); }}
* @param $data * View shown if data has not been entered yet */function formView($data) {
?> <form method=get action=message.php> <label for='message_label'>Enter your message here:</label> <input type='text' name='viewdata' size='20'/> <input type='submit' value='Submit'/> </form>
<?php}
* @param $data * View Shown if data is entered */function seenWordsView($data) {
?> <h1>Words Seen</h1> <?php foreach ($data as $output) { echo "<div>$output<div>"; } ?> <a href="./message.php">Link Back</a> <?php
// control which view based on if data is true
$data = $_GET; if ($data) { seenWordsView($data); } else { formView($data); }}
// no data entered yet --> output form to get the data
?> <form method="get" action="message.php"> <label> Enter your message here: </label> <input type="text" name="textbox" size="10" /> <input type="submit" value="Submit"/> </form> <?php}
// show the words that were entered into the form (each in own div tag)
?> <h1> Words Seen </h1> <div> The words you entered are: </div> <?php foreach ($data as $seenWord) { echo "<div>"; echo $seenWord; echo "<div>"; } ?>}
<a href="./message.php">Click</a> to submit again <?php
<?php function messageController() { $data = $_GET; formView($data); if ($data != NULL) { ob_clean(); // clears the formView to prepare the page for the seenWordsView $output = str_replace(" ", "</div><div>", $data["message_text"]); seenWordsView($output); } } function formView($data) { ?> <form method="get" action="message.php"> <label for="message_text">Enter your message here:</label> <input type="text" name="message_text" size="10" /> <input type="submit"/> </form> <?php } function seenWordsView($data) { ?> <head>Words Seen</head> <?php echo "<div>$data</div>" ?> <a href="message.php">Back to form</a> <?php } messageController();(Edited: 2016-02-25)
$data=($_GET); if($data) { seenWordsView($data); } else { formview($data); }} function formView($data) {
// $data has any data set up from the controller //outputs the message form ?> <form method="get" action="message.php"> <label for="input_field">Enter the text</label> <input type="text" name ="input_field" size="25" /> <input type="submit" name="submit" value="Submit form"/> </form> <?php} function seenWordsView($data) {
//outputs seen words, allowed a foreach loop and to //echo variables. Not allowed to call preg_ functions or explode ?> <h1>words that are seen in the textfield</h1> <?php foreach($data as $h) echo "<div>$h</div>"; ?><a href="./message.php">link back</a> <?php } messageController(); ?>
//decide which view to use and set up data for output
if(empty($_POST['data'])){ formView($_POST[data]); } else { seenWordsView($_POST[data]); }} function formView($data) {
// $data has any data set up from the controller //outputs the message form echo "<form method='POST' action='<?php echo $_SERVER[PHP_SELF];?>'><label for='input'>Enter your message here:<input type='text' id='input' name='data'><input type='submit' value='Submit'></form>";} function seenWordsView($data) {
//outputs seen words, allowed a foreach loop and to //echo variables. Not allowed to call preg_ functions or explode $words = explode(" ", $data); echo "<h1>Words Seen</h1>"; foreach ($words as $value) { echo "<div>". $value ."</div>"; } echo "Click <a href='/message.php'>here</a> to go back to the form page ";} messageController();