Validating Froms in PHP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Validating Froms in PHP

Postby arpitvavadia » 29. September 2008 05:05

Hi ! I have a form , which is validated byPHP and I want to redisplay the form with all the details , if some fields are missing. While redisplaying the form , all the data which the user has been already entered should remain as it is. Following is the code , could you check for the error .

Code: Select all
<html>
<head>
<title> Personal Detail Form </title>
<style type = "text/css">
   label {font-family:Arial, sans-serif; font-weight:bold;}
   .Text {font-style:italic; }   

</style>

</head>
<Body>

<?php
 if (!$_POST['submit'])
{
//Write the HTML Code to Display the form
?>

<Form name = "form1"  id = "myForm" method= "post" action = "<?=$_SERVER['PHP_SELF']?>">
<Table>
<TR>
   <TD> <Label for "TITL"> Title </Label></TD>
   <TD><SELECT name = "TITL" id = "TITL" size = "1" Title = "Select Title">
      <option> Mr </option>
           <option> Mrs </option>
      <option> Miss </option>
   </SELECT> </TD>
</TR>

<TR>
   <TD> <Label for= "FNAME">First Name </Label></TD>
   <TD><INPUT TYPE = "text" name = "FNAME" id = "FNAME" SIZE = "25" TITLE = "First Name" CLASS = "Text"></TD>
</TR>

<TR>
   <TD><LABEL for = "LNAME">Last Name </Label></TD>
   <TD><INPUT TYPE = "text" name = "LNAME" id = "LNAME" SIZE = 20 TITLE= "Last Name" CLASS = "Text"></TD>
</TR>

<TR>
   <TD><LABEL for = "UNAME">User Name </Label></TD>
   <TD><INPUT TYPE = "text" name = "UNAME" id = "LNAME" SIZE = 20 TITLE= "User Name" CLASS = "Text"></TD>
</TR>

<TR>
   <TD><LABEL for = "PASS1">Password </Label></TD>
   <TD><INPUT TYPE = "password" name = "PASS1" id = "PASS" SIZE = 20 TITLE= "Password" CLASS = "Text"></TD>
</TR>

<TR>
   <TD><LABEL for = "PASS2">Password Again </Label></TD>
   <TD><INPUT TYPE= "password" name = "PASS2" id= "PASS2" SIZE = 20 TITLE = "Password Again" CLASS = "Text"></TD>
</TR>
<tr>
<td></td>
<td> <INPUT TYPE = "submit" name = "submit" VALUE = "Send Form ">

</table>
</Form>

<?php
}
else
{
//Retriving the fields

$TITLE = $_POST['TITL'];
$FNAME = $_POST ['FNAME'];
$LNAME = $_POST ['LNAME'];
$UNAME = $_POST ['UNAME'];
$PASS1 = $_POST ['PASS1'];
$PASS2 = $_POST['PASS2'];

//Verfiying that that all the fields are entered
// Second Part of the Exercise
if (empty($FNAME))
{

    echo "<br> <b> $FNAME Enter Your First Name <b> <br>";
    exit (0);
   

}
if (empty($LNAME))
{
    echo "<br><b> Enter Your Last Name <b> <br>";
    exit (-1);
}
if(empty($UNAME))
{
   echo "<br> <b>Enter Your User Name <b> <br>";
   exit (-1);
}
if (empty($PASS1))
{
    echo "<br> <b> Enter Your Password <b><br>";
    exit (-1);
}
if(empty ($PASS2)) 
{
   echo "<br><b> Enter Your CONFRIM Password <b><br>";
   exit (-1);
}

//Checking up on the password details

if (strcmp($PASS1,P$PASS2)) != 0
{
    echo "Your password and confirm password are not the same ";
     exit (-1);
}


//Displaying the details

echo "<b> First Name </b> :- $TITLE . $FNAME <BR>";
echo "<B> Last Name </B> :- $LNAME <BR>";
echo "<B> User Name </B> :- $UNAME <BR>";
echo "<B> Password </B> :- $PASS1 <BR>";
echo "<B> Confrim Password </B>:- $PASS2 <BR>";
//exit(0);
}
?>
</Body>
</HTML>

[/quote]
arpitvavadia
 
Posts: 2
Joined: 16. September 2008 07:16

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 179 guests