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/Lab09/ |
Upload File : |
<? // JimMartinson/CST1146/Labs/Lab09/Lab09.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 form validation. <br><b class="warning">Warning: Do not perform this lab until <?=labLink(8,false,'')?> have been performed. <br>The <b>application.php</b> file with the formValue() function from lab 8 are 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>Code a PHP file to control a form: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Include the <b class="copyText">application.php</b> file.</li> <li>Include the <b class="copyText"><?=$saveFilename?>_Begin.php</b> file.</li> <li>If <b class="php">$f['task']</b> equals <b>'Update'</b> then require the <b class="copyText"><?=$saveFilename?>_Validate.php</b> file.</li> <li>Display the value of the <b class="php copyText">$message</b> variable. <span class="note">Simply output the variable, do not use var_dump().</span></li> <li>If <b class="php">$f['task']</b> equals either <b class="copyText">'error'</b> or <b class="copyText">NULL</b> then require the <b class="copyText"><?=$saveFilename?>_Form.php</b> file.</li> <li>If <b class="php">$f['task']</b> does not equal any of the three values above: <ol> <li>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText">Programming error</b>.</li> <li>Display some text notifying the user that there is a problem.</li> <li>Call the <b class="php">endPage</b> function</li> </ol> </li> <li>Save the <b><?=$saveFilename?>.php</b> file.</li> </ol> </li> <!-- 3 --> <li>Code a PHP file to initialize some variables: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_Begin.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Set <b class="php copyText">$f</b> equal to the return value of <b class="php">formValue()</b>.</li> <li>Use the <b class="copyText">isset()</b> function or some other method to ensure the following variables are set: <ol> <li><span class="php copyText">$f['firstName']</span>.</li> <li><span class="php copyText">$f['lastName']</span>.</li> <li><span class="php copyText">$f['gender']</span>.</li> <li><span class="php copyText">$f['emailAddress']</span>.</li> <li><span class="php copyText">$f['phoneNmber']</span>.</li> <li><span class="php copyText">$f['task']</span>.</li> <li><span class="php copyText">$firstNameError</span>.</li> <li><span class="php copyText">$lastNameError</span>.</li> <li><span class="php copyText">$genderError</span>.</li> <li><span class="php copyText">$emailAddressError</span>.</li> <li><span class="php copyText">$phoneNmberError</span>.</li> <li><span class="php copyText">$message</span>.</li> </ol> If they are not already set, set then equal to <b class="copyText">NULL</b>. <br><span class="note">This could be done by setting <span class="copyText">$f['index']</span> equal to <span class="copyText">formValue('index')</span> or with an if statement.</span> </li> <li>Save the <b><?=$saveFilename?>_Begin.php</b> file.</li> </ol> </li> <!-- 4 --> <li>Code a PHP file to display 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>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText"><?=$userFullName?> profile</b>.</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 <b class="copyText"><?=$saveFilename?>.php</b> upon submit. <br><span class="note">This could be itself, as <?=$saveFilename?>.php is the primary page that includes this file.</span> </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_profile</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">firstName</b> with a label of <b class="copyText code">First name:</b> and a <b class="html">value</b> equal to the value of <b class="php copyText">$f['firstName']</b>. <br>This field must be marked as required. <br>If the <b class="php copyText">$firstNameError</b> variable has a value, display it. <span class="note">Simply output the variable, do not use var_dump().</span> </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">lastName</b> with a label of <b class="copyText code">Last name:</b> and a <b class="html">value</b> equal to the value of <b class="php copyText">$f['lastName']</b>.</li> <li>A set of radio buttons named <b class="copyText html">gender</b> with labels and a button for <b class="copyText html">Female</b>, <b class="copyText html">Male</b>, and <b class="copyText html">Other</b>. <br>If the variable <b class="php">$f['gender']</b> equals <b>Female</b>, check the <b>Female</b> button. <br>If the variable <b class="php">$f['gender']</b> equals <b>Male</b>, check the <b>Male</b> button. <br>If the variable <b class="php">$f['gender']</b> equals <b>Other</b>, check the <b>Other</b> button. <br>This field must be marked as required. <br>If the <b class="php copyText">$genderError</b> variable has a value, display it. <span class="note">Simply output the variable, do not use var_dump().</span> </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">emailAddress</b> with a label of <b class="copyText code">Email address:</b> and a <b class="html">value</b> equal to the value of <b class="php copyText">$f['emailAddress']</b>. <br>This field must be marked as required. <br>If the <b class="php copyText">$emailAddressError</b> variable has a value, display it. <span class="note">Simply output the variable, do not use var_dump().</span> </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">phoneNmber</b> with a label of <b class="copyText code">Phone number:</b> and a <b class="html">value</b> equal to the value of <b class="php copyText">$f['phoneNmber']</b>. <br>This field must be marked as required. <br>If the <b class="php copyText">$phoneNmberError</b> variable has a value, display it. <span class="note">Simply output the variable, do not use var_dump().</span> </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 <b class="html">value</b> of <b class="copyText code">Update</b>.</li> </ol> </li> <li>Call the <b class="php">endPage</b> function</li> <li>Save the <b><?=$saveFilename?>_Form.php</b> file.</li> </ol> </li> <!-- 5 --> <li>Code a PHP file to process the form and check for errors: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_Validate.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor. <span class="note">A good place to look for regular expressions for validation is <a href="https://regexlib.com/">RegExLib.com</a>. Remember to modify them to work with pregmatch.</span> </li> <li>Validate the following form variable values with the rules stated: <ol> <li>Validate <span class="php copyText">$f['firstName']</span> and ensure it is not an empty string. If it is invalid, set: <ol> <li><span class="php copyText">$f['task']</span> equal to <span class="copyText">'error'</span>.</li> <li><span class="php copyText">$firstNameError</span> equal to a descriptive error message.</li> </ol> </li> <li>Allow anything (including an empty string) for <span class="copyText">$f['lastName']</span></li> <li>Validate <span class="php copyText">$f['gender']</span> and ensure it has a valid value. If it is invalid, set: <ol> <li><span class="php copyText">$f['task']</span> equal to <span class="copyText">'error'</span>.</li> <li><span class="php copyText">$genderError</span> equal to a descriptive error message.</li> </ol> </li> <li>Validate <span class="php copyText">$f['emailAddress']</span> and ensure it matches a valid email format. If it is invalid, set: <ol> <li><span class="php copyText">$f['task']</span> equal to <span class="copyText">'error'</span>.</li> <li><span class="php copyText">$emailAddressError</span> equal to a descriptive error message.</li> </ol> </li> <li>Validate <span class="php copyText">$f['phoneNmber']</span> and ensure it matches a valid phone number format. If it is invalid, set: <ol> <li><span class="php copyText">$f['task']</span> equal to <span class="copyText">'error'</span>.</li> <li><span class="php copyText">$phoneNmberError</span> equal to a descriptive error message.</li> </ol> </li> </ol> </li> <li>If there are any errors, set the <b class="php copyText">$message</b> variable to <b class="html copyText"><h2 style="color:red;">There are errors on the form.</h2></b>.</li> <li>If there are no errors, set the <b class="php copyText">$message</b> variable to <b class="html copyText"><h2>Thank you for entering your profile!</h2></b> and set <b class="php copyText">$f['task']</b> to <b class="copyText">NULL</b>.</li> <li>Save the <b><?=$saveFilename?>_Validate.php</b> file.</li> </ol> </li> <!-- 6 --> <li>Verify that your page displays errors. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open up a browser.</li> <li>In the address bar enter <b class="copyText">http://localhost/CST1146/<?=$evaluationName?>/</b> and hit enter.</li> <li>Click on your <b><?=$saveFilename?>.php</b> file. <li>Submit the form without entering any values.</li> <? /** / ?> <br>You should see a page like:<br> <? BrowserBegin('Lab '.$evaluationNumber.' - '.$userFullName,'http://localhost/CST1146/'.$saveFilename.'.php',820); ?> <h1 class="left">Lab <?=$evaluationNumber?> - <?=$userFullName?></h1> <h2>__3__</h2> <?php ?> <h2>__4__</h2> <?php ?> <h2>__5__</h2> <?php ?> <h2>__6__</h2> <?php ?> <h2>__7__</h2> <?php ?> <h2>__8__</h2> <?php ?> <? 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?>_Error.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> <span class="note normal">You should also test the page to ensure other entry errors like invalid email or phone number are displayed.</span> </li> <!-- 7 --> <li>Verify that your page shows when everything is OK. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open up a browser.</li> <li>In the address bar enter <b class="copyText">http://localhost/CST1146/<?=$evaluationName?>/</b> and hit enter.</li> <li>Click on your <b><?=$saveFilename?>.php</b> file. <li>Enter valid values into the form an submit it.</li> <? /** / ?> <br>You should see a page like:<br> <? BrowserBegin('Lab '.$evaluationNumber.' - '.$userFullName,'http://localhost/CST1146/'.$saveFilename.'.php',820); ?> <h1 class="left">Lab <?=$evaluationNumber?> - <?=$userFullName?></h1> <h2>__3__</h2> <?php ?> <h2>__4__</h2> <?php ?> <h2>__5__</h2> <?php ?> <h2>__6__</h2> <?php ?> <h2>__7__</h2> <?php ?> <h2>__8__</h2> <?php ?> <? 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?>_OK.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> <!-- 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.'.php', $saveFilename.'_Begin.png', $saveFilename.'_Form.png', $saveFilename.'_Validate.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. ?>