Question
Write the code that processes the data entered by the user 1. Open the index.php file for this application and review the code. Note that
Write the code that processes the data entered by the user
1. Open the index.php file for this application and review the code. Note that it doesnt process the data thats entered into the text boxes.
2. Open the string_tester.php file for this application and review the code. Note that the PHP code that displays the $message variable uses the nl2br function to convert new line characters to tags.
3. Add the code that uses the data thats entered into the text box controls to display a message thats formatted like this:
Hello Joel, Thank you for entering this data:
Name: Joel Murach Email: joel@murach.com Phone: 415-123-4567
When formatting this message, use escape sequences to insert new line characters.
4. Make sure the user enters a name, but only display the first name in the message. For both the complete name and the first name, capitalize the first letter of the name only.
5. Make sure the user enters an email address, and make sure that this address contains at least one @ sign and one dot character (.).
6. Make sure the phone number contains at least seven digits, not including formatting characters such as dashes, spaces, and parenthesis.
7. Test the application to make sure it works correctly.
index.php
//process $action = filter_input(INPUT_POST, 'action');
switch ($action) { case 'process_data': $name = filter_input(INPUT_POST, 'name'); $email = filter_input(INPUT_POST, 'email'); $phone = filter_input(INPUT_POST, 'phone');
/************************************************* * validate and process the name ************************************************/ // 1. make sure the user enters a name // 2. display the name with only the first letter capitalized
/************************************************* * validate and process the email address ************************************************/ // 1. make sure the user enters an email // 2. make sure the email address has at least one @ sign and one dot character
/************************************************* * validate and process the phone number ************************************************/ // 1. make sure the user enters at least seven digits, not including formatting characters // 2. format the phone number like this 123-4567 or this 123-456-7890
/************************************************* * Display the validation message ************************************************/ $message = "This page is under construction. " . "Please write the code that processes the data.";
break; } include 'string_tester.php'; ?>
string_tester.php
String Tester
Message:
main.css
body { font-family: Arial, Helvetica, sans-serif; } main { width: 450px; margin: 0 auto; padding: 1em; background: white; border: 2px solid navy; } h1 { margin-top: 0; color: navy; } label { display: block; width: 8em; text-align: right; margin: 0 0 .5em; padding: 0 1em; float: left; } input, select { display: block; float: left; margin-bottom: .5em; margin-top: 0; } br { clear: left; }
.
The results (assuming the email lacks the @ character) will resemble the image in Figure 2.
String Tester Name Phone Number Submit Message: Enter some data and click on the ubit button. Figure 1 String Tester Name Phone Number Submit Message: Enter some data and click on the ubit button. Figure 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started