Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.