Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an XHTML form that collects a name, address, phone number, and zip code.

ID: 3722524 • Letter: C

Question

Create an XHTML form that collects a name, address, phone number, and zip code. The phone number must be input in the format of ddd-ddd-dddd and the zip code must be in the format of ddddd-dddd. Write a PHP script that checks the submitted information and verifies the format of the phone number and zip code. If the information correctly matches the format, display the information contained in the submitted form. If the data does not match the required format, return an error message exampling the format problem.

Explanation / Answer

Please create the files with the given names

########## index.html ############3

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Title of document</title>

</head>

<body>

<h2>Insert Info</h2>

<form action="insert.php">

Name:<input type="text" name="name" /><br/>

Address Line 1:<input type="text" name="addr1"/><br/>

phone number:<input type="text" name="no"/><br/>

zip code<input type="text" name="zip"/><br/>

<input type="submit" value="insert" />

<input type="reset" value="reset" />

</form>

</body>

</html>

####### insert.php ###########

<?php
# take inputs & store in local variables
$name = $_REQUEST['name'];
$addr1 = $_REQUEST['addr1'];
$no = $_REQUEST['no'];
$zip = $_REQUEST['zip'];

if (empty($name) | empty($addr1) | empty($no) | empty($zip)) {
die("please fill all elements");
}
if (preg_match("/^d{3}-d{3}-d{4}$/", $no)) {
} else {
echo "invalid phone number format,it should be in ddd-ddd-dddd format eg:555-666-0606";
}
if (preg_match("/^d{5}-d{4}$/", $zip)) {
} else {
echo "invalid zip code format,it should be in ddddd-dddd format eg:55555-0606";
}
if (preg_match("/^d{3}-d{3}-d{4}$/", $no) & preg_match("/^d{5}-d{4}$/", $zip)) {
echo "name is $name address is $addr1 number is $no zip code is $zip";
}

#################################################################

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote