Jump to content

Please help...


aub

Recommended Posts

Design a form that accept your first name, last name and email address. Use GET for posting the form into the same php page, print out the result:

(first_name, last_name, and email_address after the form is being submitted, you must validate your first_name, last_name are alphabetic, and your email address is valid. Also all fields must be mandatory. 

I don't know how to make first name and last name alphabetic and email address valid. 

This is my code:
 

<html xmlns='http://www.w3.org/1999/xhtml'>
	<head>
		<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
		<title>PHP Scripting</title>
	</head>
<body>
<h1>TASK 3: Question 4</h1>

<?php 

if (isset($_GET['Submit'])) {
	echo "inside the form". $_GET['Submit'] . "<br>";

$firstname = $_GET['fname'];
$lastname = $_GET['lname'];
$DOB = $_GET['dob'];


if(empty($_GET['fname']) || empty($_GET['lname']) || empty($_GET['dob'])) {
    echo 'Please fill in all of the fields.';
} else {
    $firstname = $_GET['fname'];
    $lastname = $_GET['lname'];
    $dob = $_GET['dob'];
    if(ucfirst($firstname) != $firstname || ucfirst($lastname) != $lastname) {
      echo 'The first letter of your first and last name must be in upper case.';
    } else {
      echo 'Thank you ' . htmlspecialchars($firstname) . ' ' . htmlspecialchars($lastname) . ', for entering your date of birth: ' . htmlspecialchars($dob) . '<br />';
    }
} 
		
} else {

?>

<form action="getform.php", method="get">


	<p>First Name: <input type="text" name="fname" value=""/></p>
	
	<p>Last Name: <input type="text" name="lname" value=""/></p>
	
	<p>DOB: <input type="date" name="dob" value=""/></p>

	<p><input type="submit" name="Submit" value="Submitted"/></p>


<?php 
echo "not in form yet";
echo "<br>" . $_SERVER['PHP_SELF'];
}
?>
Link to comment
https://forums.phpfreaks.com/topic/288062-please-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.