Link to home
Start Free TrialLog in
Avatar of xenoula
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['password']);  
$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','$pass','$forename','$surname','$fulladdress','$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
ASKER CERTIFIED SOLUTION
Avatar of malaiac
malaiac

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xenoula
xenoula

ASKER

malaiac thank you very much for your help.
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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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->IsFormSubmitted() && $feedback_form->IsAllRequiredSet())
    {
        $sender         = $feedback_form->DisplayValue('sender');
        $email          = $feedback_form->DisplayValue('email');
        $recipient      = $feedback_form->DisplayValue('recipient');
        $message        = $feedback_form->DisplayValue('message');
        $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} &lt;{$email}&gt;</p>
    </div>
</body>
</html>
MAILMESSAGE;
// Forming of message comlete.

        mail("feedback@example.com", $mail_subject, $mail_message, $mail_headers)
    }
?>
<?php $feedback_form->OpenForm(false); ?>
    <?php $feedback_form->DisplayWarning("Error! 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->DisplayTitle("sender", "Sender:"); ?></p></td>
                <td>
                    <?php $feedback_form->DisplayInput("sender", null, "maxlength=\"128\" style=\"font-size: x-small; width: 100%;\"", true); ?>
                    <div class="form_example"><b>Example:</b> Ivanov Ivan Ivanovich</div>
                </td>
            </tr>
            <tr>
                <td><p><?php $feedback_form->DisplayTitle("email", "E-mail:"); ?></p></td>
                <td>
                    <?php $feedback_form->DisplayInput("email", null, "maxlength=\"128\" style=\"font-size: x-small; width: 100%;\"", true); ?>
                    <div class="form_example"><b>Example:</b> ivan@example.com</div>
                </td>
            </tr>
            <tr>
                <td><p><?php $feedback_form->DisplayTitle("recipient", "Recipient:"); ?></p></td>
                <td>
                    <?php
                        $recipient_list     = array(
                            "info" => "Info",
                            "ads" => "Advertisement",
                            "support" => "Support"
                        );
                        $feedback_form->DisplaySelect("recipient", $recipient_list, "info", "style=\"font-size: x-small; width: 100%;\"", true);
                    ?>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <p><?php $feedback_form->DisplayTitle("message", "Message:"); ?></p>
                    <?php $feedback_form->DisplayTextArea("message", null, "rows=\"4\" style=\"width: 100%;\"", true); ?>
                </td>
            </tr>
        </table>
        <p style="text-align: right; margin-right: 5px;"><?php $feedback_form->DisplaySubmit("Send!", null); ?></p>
    </div>
<?php $feedback_form->CloseForm(); ?>