xenoula
asked on
How to display the error of missing field under the specifc field
Hello everyone,
I have created a sign up form where the user fill in 13 fields in which 5 of them are required. The required fields are the following :forename,surname,username ,password, confirm password.I have manage to check if the user has enter details in the fields using the function strlen( ). For the password and confirm password i am also checking if these two matches and at the username i also check if the username alreday exist in the database. The problem is that if the user has either forgot to put data or already exist or missmatch the password it displays the same error for the password and also erase all the other fields which has already been filled. What i would like help with is to manage and display the correct error message under the field that has the error and also to keep the data to the fields that has the correct details.
I have post also the code i have already write.I would appreciate your help.
<!--Here is the code i have written -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?
include "dbconn.php";
$title=$_POST['title'];
$forename=$_POST['forename '];
$surname=$_POST['surname'] ;
$username= $_POST['username'];
$pass=sha1($_POST['passwor d']);
$confirm=$_POST['confirm'] ;
$email=$_POST['email'];
$address1=$_POST['address1 '];
$address2=$_POST['address2 '];
$fulladdress="$address1 "." $address2";
$town=$_POST['town'];
$county=$_POST['county'];
$postcode=$_POST['postcode '];
?>
<html>
<head>
<title>Confirm User sign up</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.error {
font-family: "Times New Roman", Times, serif;
color: #99FF33;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
color: #009900;
}
-->
</style>
</head>
<body>
<?
if (strlen($forename)<0)
{ echo "no forename"; }
elseif (!$pass==$confirm){
echo "no match password";}
elseif (strlen($surname)<0)
{ echo "no surname"; }
elseif (strlen($username)<0)
{ echo "no surname"; }
elseif ($username==$row['username '])
{ echo "this username already exist,choose another"; }
else{
//echo "The password match the confirm password";
$query="Insert into Customers (`title`,`username`, `password`, `firstname`, `lastname`, `address`, `town`, `county`, `postcode`, `email`)
values ('$title','$username','$pa ss','$fore name','$su rname','$f ulladdress ','$town', '$county', '$postcode ','$email' )";
$rs=mysql_query($query);
if ($rs){ echo $forename ."thank you for signing in the website ";}
else { echo "An error occured";}
}
?>
<input name="title" type="hidden" value="<? echo $title;?>">
<input name="forename" type="hidden" value="<? echo $forename;?>">
<input name="surname" type="hidden" value="<? echo $surname;?>">
<input name="username" type="hidden" value="<? echo $username;?>">
<input name="password" type="hidden" value="<? echo $pass;?>">
<input name="confirm" type="hidden" value="<? echo $confirm;?>">
<input name="email" type="hidden" value="<? echo $email;?>">
<input name="address1" type="hidden" value="<? echo $address1;?>">
<input name="address2" type="hidden" value="<? echo $address2;?>">
<input name="town" type="hidden" value="<? echo $town;?>">
<input name="county" type="hidden" value="<? echo $county;?>">
<input name="postcode" type="hidden" value="<? echo $postcode;?>">
</body>
</html>
<!--end of the code-->
Thank you in advance,
Xenia
I have created a sign up form where the user fill in 13 fields in which 5 of them are required. The required fields are the following :forename,surname,username
I have post also the code i have already write.I would appreciate your help.
<!--Here is the code i have written -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?
include "dbconn.php";
$title=$_POST['title'];
$forename=$_POST['forename
$surname=$_POST['surname']
$username= $_POST['username'];
$pass=sha1($_POST['passwor
$confirm=$_POST['confirm']
$email=$_POST['email'];
$address1=$_POST['address1
$address2=$_POST['address2
$fulladdress="$address1 "." $address2";
$town=$_POST['town'];
$county=$_POST['county'];
$postcode=$_POST['postcode
?>
<html>
<head>
<title>Confirm User sign up</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.error {
font-family: "Times New Roman", Times, serif;
color: #99FF33;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
color: #009900;
}
-->
</style>
</head>
<body>
<?
if (strlen($forename)<0)
{ echo "no forename"; }
elseif (!$pass==$confirm){
echo "no match password";}
elseif (strlen($surname)<0)
{ echo "no surname"; }
elseif (strlen($username)<0)
{ echo "no surname"; }
elseif ($username==$row['username
{ echo "this username already exist,choose another"; }
else{
//echo "The password match the confirm password";
$query="Insert into Customers (`title`,`username`, `password`, `firstname`, `lastname`, `address`, `town`, `county`, `postcode`, `email`)
values ('$title','$username','$pa
$rs=mysql_query($query);
if ($rs){ echo $forename ."thank you for signing in the website ";}
else { echo "An error occured";}
}
?>
<input name="title" type="hidden" value="<? echo $title;?>">
<input name="forename" type="hidden" value="<? echo $forename;?>">
<input name="surname" type="hidden" value="<? echo $surname;?>">
<input name="username" type="hidden" value="<? echo $username;?>">
<input name="password" type="hidden" value="<? echo $pass;?>">
<input name="confirm" type="hidden" value="<? echo $confirm;?>">
<input name="email" type="hidden" value="<? echo $email;?>">
<input name="address1" type="hidden" value="<? echo $address1;?>">
<input name="address2" type="hidden" value="<? echo $address2;?>">
<input name="town" type="hidden" value="<? echo $town;?>">
<input name="county" type="hidden" value="<? echo $county;?>">
<input name="postcode" type="hidden" value="<? echo $postcode;?>">
</body>
</html>
<!--end of the code-->
Thank you in advance,
Xenia
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Now the exaple of using this class, to understand how it works:
<?php
$feedback_form = new HtmlForm("feedback", "Feedback/", "post", "multipart/form-data");
if ($feedback_form->IsFormSub mitted() && $feedback_form->IsAllRequi redSet())
{
$sender = $feedback_form->DisplayVal ue('sender ');
$email = $feedback_form->DisplayVal ue('email' );
$recipient = $feedback_form->DisplayVal ue('recipi ent');
$message = $feedback_form->DisplayVal ue('messag e');
$mail_subject = "Feedback :: {$recipient}";
$mail_headers = "From: \"{$sender}\" <{$email}>\n";
$mail_headers .= "Reply-To: \"{$sender}\" <{$email}>\n";
$mail_headers .= "Content-Type: text/html; charset=\"utf-8\"\n";
// Forming message
$mail_message = <<<MAILMESSAGE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Feedback</title>
<style><!--
body
{
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
div
{
background-color: #FDF5E6;
border: solid 1px #B22222;
margin: 5px;
padding: 5px;
}
p
{
margin: 0px;
}
--></style>
</head>
<body>
<div>
<h1>Feedback :: {$recipient}</h1>
<p>{$message}</p>
<p>{$sender} <{$email}></p>
</div>
</body>
</html>
MAILMESSAGE;
// Forming of message comlete.
mail("feedback@example.com ", $mail_subject, $mail_message, $mail_headers)
}
?>
<?php $feedback_form->OpenForm(f alse); ?>
<?php $feedback_form->DisplayWar ning("Erro r! You must fiil up all necessary fields."); ?>
<div class="box">
<table width="100%" border="0">
<colgroup>
<col width="40%" valign="top" /><col width="60%" valign="top" align="right" />
</colgroup>
<tr>
<td><p><?php $feedback_form->DisplayTit le("sender ", "Sender:"); ?></p></td>
<td>
<?php $feedback_form->DisplayInp ut("sender ", null, "maxlength=\"128\" style=\"font-size: x-small; width: 100%;\"", true); ?>
<div class="form_example"><b>Ex ample:</b> Ivanov Ivan Ivanovich</div>
</td>
</tr>
<tr>
<td><p><?php $feedback_form->DisplayTit le("email" , "E-mail:"); ?></p></td>
<td>
<?php $feedback_form->DisplayInp ut("email" , null, "maxlength=\"128\" style=\"font-size: x-small; width: 100%;\"", true); ?>
<div class="form_example"><b>Ex ample:</b> ivan@example.com</div>
</td>
</tr>
<tr>
<td><p><?php $feedback_form->DisplayTit le("recipi ent", "Recipient:"); ?></p></td>
<td>
<?php
$recipient_list = array(
"info" => "Info",
"ads" => "Advertisement",
"support" => "Support"
);
$feedback_form->DisplaySel ect("recip ient", $recipient_list, "info", "style=\"font-size: x-small; width: 100%;\"", true);
?>
</td>
</tr>
<tr>
<td colspan="2">
<p><?php $feedback_form->DisplayTit le("messag e", "Message:"); ?></p>
<?php $feedback_form->DisplayTex tArea("mes sage", null, "rows=\"4\" style=\"width: 100%;\"", true); ?>
</td>
</tr>
</table>
<p style="text-align: right; margin-right: 5px;"><?php $feedback_form->DisplaySub mit("Send! ", null); ?></p>
</div>
<?php $feedback_form->CloseForm( ); ?>
<?php
$feedback_form = new HtmlForm("feedback", "Feedback/", "post", "multipart/form-data");
if ($feedback_form->IsFormSub
{
$sender = $feedback_form->DisplayVal
$email = $feedback_form->DisplayVal
$recipient = $feedback_form->DisplayVal
$message = $feedback_form->DisplayVal
$mail_subject = "Feedback :: {$recipient}";
$mail_headers = "From: \"{$sender}\" <{$email}>\n";
$mail_headers .= "Reply-To: \"{$sender}\" <{$email}>\n";
$mail_headers .= "Content-Type: text/html; charset=\"utf-8\"\n";
// Forming message
$mail_message = <<<MAILMESSAGE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Feedback</title>
<style><!--
body
{
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
div
{
background-color: #FDF5E6;
border: solid 1px #B22222;
margin: 5px;
padding: 5px;
}
p
{
margin: 0px;
}
--></style>
</head>
<body>
<div>
<h1>Feedback :: {$recipient}</h1>
<p>{$message}</p>
<p>{$sender} <{$email}></p>
</div>
</body>
</html>
MAILMESSAGE;
// Forming of message comlete.
mail("feedback@example.com
}
?>
<?php $feedback_form->OpenForm(f
<?php $feedback_form->DisplayWar
<div class="box">
<table width="100%" border="0">
<colgroup>
<col width="40%" valign="top" /><col width="60%" valign="top" align="right" />
</colgroup>
<tr>
<td><p><?php $feedback_form->DisplayTit
<td>
<?php $feedback_form->DisplayInp
<div class="form_example"><b>Ex
</td>
</tr>
<tr>
<td><p><?php $feedback_form->DisplayTit
<td>
<?php $feedback_form->DisplayInp
<div class="form_example"><b>Ex
</td>
</tr>
<tr>
<td><p><?php $feedback_form->DisplayTit
<td>
<?php
$recipient_list = array(
"info" => "Info",
"ads" => "Advertisement",
"support" => "Support"
);
$feedback_form->DisplaySel
?>
</td>
</tr>
<tr>
<td colspan="2">
<p><?php $feedback_form->DisplayTit
<?php $feedback_form->DisplayTex
</td>
</tr>
</table>
<p style="text-align: right; margin-right: 5px;"><?php $feedback_form->DisplaySub
</div>
<?php $feedback_form->CloseForm(
ASKER
Actually i have a form called signup.php where the user fill in the details and when he click the submit button it goes to the
page confirmsignup.php.
I put the code you post here but when i click on the submit button it just display a new form without keeping the data and catching the errror.
I think someting i might doing wrong.
What u think?