I have simple form that asks the user to input their first name, last name, email address, and desired username.
Now I have also done some error checking to make sure that those required fields are populated.
My question is if they enter, lets say their first name, last name and desired username I still want it to error, saying “you have not filled out all required fields” because they have not filled in their email address and include the form html file below so they can fill in the required field before the script continues.
How can I keep the details of what they had input into the form below so they only have to update the field they had not entered any thing into.
Here’s my Form
<HTML>
<HEAD>
<TITLE>Login Form</TITLE>
</HEAD>
<BODY>
<TABLE border="0" cellspacing="0">
<FORM action="logon.php" method="POST">
<TR><TD>First name:<TD><INPUT type="text" id="first_name" name="first_name"></TD></TR>
<TR><TD>Last name:<TD><INPUT type="text" id="last_name" name="last_name"></TD></TR>
<TR><TD>Email Address:<TD><INPUT type="text" id="email_address" name="email_address"></TD></TR>
<TR><TD>Desired Username:<TD><INPUT type="text" id="username" name="username"></TD></TR>
<TR><TD><INPUT type="submit" id="submit" name="submit" value="Join!"></TD></TR>
</FORM>
</TABLE>
</BODY>
</HTML>
and here’s the php script.
<?PHP
//Include Db connection script.
include('db.php');
//Create Variables from join_form.html
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
/* Check to see if they filled all required fields from the
'join_form.html' and give error if they have not */
if ((!$first_name) || (!$last_name) || (!$email_address) || (!$username)) {
echo '<STRONG>You did not enter the following required fields</STRONG><br/><br/><br/>';
if (!$first_name) {
echo 'Please enter your first name. This is a required field.<br/><br/>';
}
if (!$last_name) {
echo 'Please enter you last name. This is a required field.<br/><br/>';
}
if (!$email_address) {
echo 'Please enter your email address.<br/><br/>';
}
if (!$username) {
echo 'Please enter in your desired username. This is a required field.<br/><br/><br/>';
}
include('join_form.html'); // Show the form again.
exit(); // Stop runnning this script from here.
}
/* Now lets check if username and email address exists in the Database 'stenk' table `users`. */
Hope you all understand what I want. Should be very simple for you all but I am not sure if I need to create another form and use a value like <INPUT type="text" id="email_addess" name="email_address" value="<?php echo '$email_address'; ?>" >.
Kind regards,
Sten