Question
Assignment 2 Form Validation and PHP introduction Name Type Control Type Requirement FirstName String TextBox 50 Characters max. First letter must be capitalized. LastName String
Assignment 2
Form Validation and PHP introduction
Name | Type | Control Type | Requirement |
FirstName | String
| TextBox
| 50 Characters max. First letter must be capitalized. |
LastName | String
| TextBox
| 50 Characters max. First letter must be capitalized. |
Age
| Int |
| Shall be a valid integer. Value shall fall within range of 0 to 100. |
Gender
| String
| Radio | 50 Characters Max. First letter must be capitalized. Male, Female, NA. Only one option can be selected at any given time.
|
Height
| int
| 2 Textboxes. 1 for Feet, the other for Inches.
| Shall be a valid double (decimal) number. Max height shall be 10 feet 0 inches. |
Phone
| phone | Textbox with the max length of 12.
| Phone Phone Textbox with the max length of 12. Must be a standard 9 digit US number with or without parentheses and dashes. Both cases should be valid. The user shall not be able to type more than 12 characters in the textbox. (123) 456 7890, 123-456-7890 should both be valid. |
Address
| String
| Textbox
| Max Length 250 characters.
|
City
| String
| Textbox
| Max Length 75 Characters.
|
State
| String
| Select Option
| Select box with all 50 states in Abbreviated form displayed and capture the actual state as the value.
|
ZipCode
| String
| TextBox
| Must be a valid Zip Code. 5 digits or 5 and 4 digits separated by a hyphen. 12345 or 12345-6789 should both be valid. The textbox shall have a size of 10 and not allow the user to enter more than 10 characters. |
FavoriteColor
| String
| A range of 10 valid HTML colors in a select option control
| The Display should show the color and name of the color. The value should be the valid HTML color. Named color or HEX values can be used.
|
AboutMe | String | TextArea | A textbox with no size limit.
|
SubmitButton
| Form action
| Submit
| Invoke the submit action. |
FavoriteNumber | Int | TextBox | An integer |
- All form values must be validated to meet the required specifications upon clicking the submit button.
- Errors in the form shall be displayed next to the form control that has the error.
- The form shall only be submitted when all values in the controls are validated to meet the specifications.
- The validation scripts must reside in a separate JavaScript file include through the header of the html document.
- The Form must be structured in a readable format.
- The method of the form shall be POST.
- The action of the form shall be processform.php.
Form Processing
This next portion of the assignment focuses on using PHP to process the form.
- Create a file called processform.php.
- Assign all $POST variables to the respective counterparts following the conventions indicated in the lecture slides. For example: $FirstName = $_POST[FirstName];
- Validate that the values submitted are correct using simple if-then logic to meet the same criteria as indicated above.
There are more efficient methods that we will explore later, and you are welcome to use those so long as the data is validated.
- After the form variables are validated, the resulting php page shall do the following:
- Have the same general layout as form page. Meaning the header, footer and layout should be consistent with the home page.
- Display the results of the form in a presentable manner, either in table structure, or you can get creative. As long as the proper data is displayed with the proper field names, I wont be picky. For example: Height should be as follows: Height: 510
- You can use a mix of HTML layout and PHP to display the data, it doesnt matter to me. For example, you can do something like this:
First Name: . - Data with Invalid values should be highlighted in Red.
- Calculate a magic number by doing the following:
- Take all the numeric values of the phone number and strip out the parentheses and dashes as your first number. For example 123-456-789 will be 123456789
- Take all the numeric values of the Zipcode and strip out the dashes to form your second number. For example 12345-6789 will be 123456789
- The third number will be decimal equivalent in feet of the height. So 5 feet 10 inches will be equivalent to 5.83.
- The fourth number will be the age.
- Take the first and second number and add them to get the Quotient.
- Take the third and fourth number and add them to get the dividend.
- Finally divide the Quotient by the dividend. This is your Magic Number.
- Display your magic number as part of the output. With the text Your Magic Number is: $MagicNumber.
Ensure the processform.php works as expected and the results are displayed properly.
Show an Error message in Red if validation fails, otherwise show a success message in Green.
Provide a link to route back to the original form if validation fails.
Step 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