2016-02-24

Feb 24 Thread.

Hey Everyone,
Post your code for the Feb 24 "Let's Build Something here".
Remember if you precede each line of your code by at least one white space character it will be output preformatted in your post.
Best, Chris
Hey Everyone, Post your code for the Feb 24 "Let's Build Something here". Remember if you precede each line of your code by at least one white space character it will be output preformatted in your post. Best, Chris

-- Feb 24 Thread
<?php
function messageController() {
	$data = $_GET["textbox"];
	if ($data) 
		seenWordsView(explode(" ", $data));
	else 
		formView($data);
}
function 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
}
function seenWordsView($data) {
	# Heading
	?><h1>Words Seen</h1><?php
	foreach ($data as $word) 
		echo "<div>$word</div>";
	echo "

<a href=\"message.php?\">Back</a>";
}
messageController();
?>
(Edited: 2016-02-24)
<?php function messageController() { $data = $_GET["textbox"]; if ($data) seenWordsView(explode(" ", $data)); else formView($data); } function 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 } function seenWordsView($data) { # Heading ?><h1>Words Seen</h1><?php foreach ($data as $word) echo "<div>$word</div>"; echo "<br><br><a href=\"message.php?\">Back</a>"; } messageController(); ?>

-- Feb 24 Thread
<?php
/*
 * 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
}
//Call view controller
messageController();
(Edited: 2016-02-24)
<?php /* * 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 } //Call view controller messageController();

-- Feb 24 Thread
<?php //Tyler Jones : CS174 : Feb 24
 
// control which view based on if data is true
function messageController() {
    $data = $_GET; 
    if ($data) { 
        seenWordsView($data); 
    } else { 
        formView($data); 
    } 
}
 
// no data entered yet --> output form to get the data
function formView($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)
function seenWordsView($data) {
    ?> 
        <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
}
messageController();
(Edited: 2016-02-24)
<?php //Tyler Jones : CS174 : Feb 24 // control which view based on if data is true function messageController() { $data = $_GET; if ($data) { seenWordsView($data); } else { formView($data); } } // no data entered yet --> output form to get the data function formView($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) function seenWordsView($data) { ?> <h1> Words Seen </h1> <div> The words you entered are: </div> <?php foreach ($data as $seenWord) { echo "<div>"; echo $seenWord; echo "<div>"; } ?> <br><a href="./message.php">Click</a> to submit again <?php } messageController();

-- Feb 24 Thread
@dennis and @tyler. Your code needs to somewhere split the text field data from the form into words. As it stands now it is cycling over the $_GET fields (not words) on the page. I just updated that slide because I had been vague and send output all the words submitted on the page. I meant all the words in the text field data.
@dennis and @tyler. Your code needs to somewhere split the text field data from the form into words. As it stands now it is cycling over the $_GET fields (not words) on the page. I just updated that slide because I had been vague and send output all the words submitted on the page. I meant all the words in the text field data.

-- Feb 24 Thread
     <?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)
<?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();

-- Feb 24 Thread
Hi Alejandro,
  1. The label element should have a for attribute to indicate which form element it is for.
  2. I'm not sure why you have the ob_start and ob_clean methods in the above -- their typically used only when you want to capture the output as a string -- which we don't need to do here.
  3. You shouldn't use things like str_replace in a view, we imagine a view being written and maintained by a web designer whose expertise is design not coding.
Best, Chris
(Edited: 2016-02-25)
Hi Alejandro, # The label element should have a '''for''' attribute to indicate which form element it is for. # I'm not sure why you have the '''ob_start''' and '''ob_clean''' methods in the above -- their typically used only when you want to capture the output as a string -- which we don't need to do here. # You shouldn't use things like '''str_replace''' in a view, we imagine a view being written and maintained by a web designer whose expertise is design not coding. Best, Chris
2016-02-25

-- Feb 24 Thread
<?php function messageController() {
   $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(); ?>
<?php function messageController() { $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(); ?>

-- Feb 24 Thread
Hi Sarika,
The "for" attribute of a label needs to point to an "id" attribute of some target element not the "name" attribute. Your code doesn't output each word from the form submission in a different div, it outputs each field that was submitted instead.
Best, Chris
Hi Sarika, The "for" attribute of a label needs to point to an "id" attribute of some target element not the "name" attribute. Your code doesn't output each word from the form submission in a different div, it outputs each field that was submitted instead. Best, Chris

-- Feb 24 Thread
Here's mine:
<?php
function 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();
?>
(Edited: 2016-02-26)
Here's mine: <?php function 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(); ?>
[ Next ]
X