If the user has not filled in every field, show an error message like the one below instead of displaying their submitted data: $_REQUEST = "abc" would give a truthy value. Remember that $_REQUEST = "" would give a falsey value and Has 'var' as one of its keys it does not check to see if the value of $_REQUEST However, isset($_REQUEST) will only check if the $_REQUEST associative array This can be done by checking if a particular value has been passed by using the php function isset(). You should verify that the user did not leave any fields blank when submiting the form. Update your sucker.php file to do some basic error handling. In the real world, we would also save the provided data somewhere, but since we are not actually trying to con students into giving up their credit card numbers (rats!) we can skip this step.Įxercise 3: Verify the Existence of Data (roughly 10 minutes) The following image is an example output: You do not have to match the output exactly, but your page should at least display the submitter's name, credit card number, and credit card type (visa or mastercard) in the confirmation page. You can also embed dynamic PHP content (such as variables) in HTML mode using. Write in HTML as you would normally to display a webpage, then switch to PHP mode by opening up a PHP blocking using. Remember to switch between HTML and PHP modes. The page sucker.php will receive input from buyagrade.html and will output an HTML confirmation page. Modify buyagrade.html to POST to sucker.php. In this exercise, you will write the PHP page that will handle the submitted form data. Don't look at the source code, please!)Įxercise 2: Displaying Input Data (roughly 15 minutes) You may try our runnable solution to this exercise (so you can see how your page is supposed to look and work. Test your form to see that it is submitting the proper parameters by temporarily setting its action attribute to: Also, certain form controls also need value attributes, such as radio buttons. You need to modify this html file for the form to work properly, including the addition of name attributes to the form controls and form tags surrounding the form to be submitted. Download buyagrade.html to your disk (right-click the link and choose Save Link As.). This exercise involves creating an HTML form that POSTs its submitted data to a PHP program on a server. Don't look at the source code yet, please!)Įxercise 1: Creating a Form (roughly 10 minutes) Runnable solution ( PHP source) to this lab (so you can see how your page is supposed to look and work.Wednesday Lecture Slides: Form Validation with Regular Expressions.Will do some checks to validate the information submitted, and it will output a web page that eitherĬonfirms the submission or informs the user to try submitting again. (Note: This is just a joke! We do not suggest that you actually try to bribe us for grades.) The html pageīuyagrade.html will contain a form that submits to sucker.php. In this week's lab, we'll write code to complete a web service that allows students to submit their credit card numbers in exchange for good You probably won't have enough time to finish all of the exercises finish as much as you can within the allotted time. This lab's purpose is to give you some practice writing a PHP script that processes an HTML form. Lab 8: PHP and HTML forms (Thursday, May 22, 2008) University of Washington, CSE 190 M, Spring 2008
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |