|
-
March 27th, 2007, 08:14 AM
#1
validation using a function call in PHP
I am new to PHP.I am trying to create users using HTML controls and the validation is done in PHP as follows.I have used a template
my form is as follows......Createnewuser.php is the name of the file
<form method="post" action="Createnewuser.php" onSubmit="fun()">
<input type="text" name="txt_username"></td>
<input type="text" name="txt_userid">
<input type="password" name="txt_password" >
<input type="password" name="txt_cfrm_password">
<input type="text" name="txt_emailid">
<td><input type="submit" name="Submit" value="Create" >
<input type="submit" name="Submit" value="Cancel" onClick="Cancel_data()"></td>
</form>
*****positioning is not done properly******
once the html tag(</html>)is closed i have written the validation function fun() as follows:
function fun()
{
<?php
$flag=0;
include("Databaseconnect.php"); /*dataconnection file*/
$username=$_POST['txt_username'];
$password=$_POST['txt_password'];
$userid=$_POST['txt_userid'];
$mailid=$_POST['txt_emailid'];
$cfrm_password=$_POST['txt_cfrm_password'];
if( empty($username) || empty($userid) || empty($password) || empty($cfrm_password) || empty($mailid) )
{
$flag=1;
echo "value=$username";
echo "value=$userid"; /*trying to set values as entered*/
echo "value=$password";
echo "value=$mailid";
echo "<script language=javascript>alert('Please fill the blank fields.')</script>";
}
elseif(!(strlen($password)==strlen( $cfrm_password)))
{
$flag=1;
echo "<script language=javascript>alert('Passwords don't match')</script>";
}
elseif(!($password==$cfrm_password))
{
$flag=1;
echo "<script language=javascript>alert('password and confirm password don't match')</script>";
}
elseif(!ereg("@",$mailid))
{
$flag=1;
echo "<script language=javascript>alert('invalid emailaddress')</script>";
}
?>
}
These alert boxes are working.But when the page is loaded for the first time also i am getting the alertboxes with page on background.what is the solution?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|