U5 P1 Creating User Registration Process
pdf
keyboard_arrow_up
School
Indiana University, Purdue University, Indianapolis *
*We aren’t endorsed by this school
Course
210
Subject
Information Systems
Date
Apr 3, 2024
Type
Pages
2
Uploaded by HighnessYakMaster1036
I210 Information Infrastructure I ©Louie Zhu 1 Unit 5: Sending Data to the Server Practice 1: Creating a user registration process This process consists of two steps: Step 1 is to create the registration form. The form is built with pure HTML. Step 2 is to retrieve data from the form and process the data with PHP. Get ready 1.
Download the Practice1.zip
file from Canvas and extract all the files to htdocs\I210\Unit05
folder on your computer. Part 1: Examine the code for the registration form 2.
Start PhpStorm
and open reg_form.php inside the Practice1
folder. Run the file and preview the page in a browser. The page contains a table with two columns. The left column contains labels for form elements. Form fields are created in the right column of the table. 3.
Examine the code provided to you. Pay attention to the names assigned to all the fields. These names will be used later to retrieve field values. Part 2: Modifying the <form> tag to include the method and action attributes 4.
Modify the opening <form> tag to include the method
and action
attributes. <form name="reg" action="reg_process.php" method="post"> 5.
View the page in a browser. Ensure your form displays correctly. Try to enter some invalid data into the form to see the validation rules. We have not created the reg_process.php
page yet. Therefore, the form submission does not work yet. Part 3: Creating the registration confirmation page 6.
Open the reg_process.php
file in PhpStorm
. This file contains a table with two columns. Data are retrieved from the registration form and displayed in the right column. The left column contains labels. 7.
At the very top of the file, insert a PHP code block. Inside the PHP code block, declare variables and initialize them with empty values. $name = $zipcode = $gender = $email = $os = $newsletter = $info = ""; 8.
Ensure POST data have been received. if ($_SERVER["REQUEST_METHOD"] == "POST") { } 9.
Inside the if clause, retrieve d
ata from the form field named “name” and store it in a variable named $
name
: $name = $_POST[‘name’];
I210 Information Infrastructure I ©Louie Zhu 2 10.
Add the following lines to retrieve data from other form fields and store them in variables. $zipcode = $_POST['zipcode']; $gender = $_POST['gender']; $email = $_POST['email']; $os = $_POST['os']; $newsletter = $_POST['newsletter']; $info = $_POST['info']; 11.
Display values of these variables in appropriate cells in the right column of the table. For example, to display the first name, type: <?php echo $name ?> or <?= $name ?> 12.
Save the file and run reg_form.php
. Fill the whole form and click the Register M
e button. The Registration Conformation Page should open and display the information you filled in the form. Part 4: Modifying the registration confirmation page to use filters 13.
Open the reg_process.php
file in PhpStorm
. Modify the PHP code that retrieves form elements as follows: Current code Replace it with $name = $_POST['name'];
$name = filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING);
$zipcode = $_POST['zipcode'];
$zipcode = filter_input(INPUT_POST, "zipcode", FILTER_SANITIZE_NUMBER_INT); $email = $_POST['email'];
$email = filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL);
$newsletter = $_POST['newsletter'];
if(filter_has_var(INPUT_POST, "newsletter")) { $newsletter = $_POST['newsletter']; } else { $newsletter = "No"; }
$info = $_POST['info'];
$info = filter_input(INPUT_POST, "info", FILTER_SANITIZE_STRING);
14.
View reg_form.php in a browser. Fill the whole form and click the Register M
e button. The Registration Conformation Page should open and display the information you filled in the form as before. Even though the output is the same as before, the data are validated and sanitized now.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help