FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

here is a neat little form checker i made

 


jcortes
<?php
// EDIT THESE VERIABLES
$youremail = "youremail@host.com";
$subject = "Registration at your site here";
// CODE BEGINS HERE
//begin isset
if (isset($submit))
{
//check if first name is empty
if (empty($fname))
{
$fnamecss = "red";
$fnamebool = false;
$fnameerror = "You have left the First Name field blank<br />";
}else{
$fnamecss = "normal";
$fnamebool = true;
}
// check if last name is empty
if (empty($lname))
{
$lnamecss = "red";
$lnamebool = false;
$lnameerror = "You have left the Last Name Field Blank<br />";
}else{
$lnamecss = "normal";
$lnamebool = true;
}
// begin email check
// makes variables for search
$findat = "@";
$positionat = strpos($email, $findat);
$findsp = " ";
$positionsp = strpos($email, $findsp);
$findpd = ".";
$positionpd = strpos($email, $findpd);
//end make vars
if (empty($email))
{
$emailcss = "red";
$emailbool = false;
$emailerror = "You have left the Email field blank<br />";
}elseif (!$positionat > 0)
{
$emailcss = "red";
$emailbool = false;
$emailaterror = "You are missing an @ in your email field<br />";
}elseif ($positionsp > 0)
{
$emailcss = "red";
$emailbool = false;
$emailsperror = "You have put a space in your Email Field<br />";
}elseif (!$positionpd > 0)
{
$emailcss = "red";
$emailbool = false;
$emailpderror = "You are missing a .net/.com/ect... in your email field";
}else{
$emailcss = "normal";
$emailbool = true;
}
// start check of passwords
//first password
if (empty($pass))
{
$passcss = "red";
$passbool = false;
$passerror = "You have left the First Password field empty<br />";
}else{
$passcss = "normal";
$passbool = true;
}
//Verify password
if (empty($passverify))
{
$passverifycss = "red";
$passverifybool = false;
$passverifyerror = "You have left the Second Password field empty<br />";
}else{
$passcss = "normal";
$passverifybool = true;
}
//Check if password match
if (!empty($pass) && !empty($passverify))
{
if ($pass !== $passverify)
{
$passcss = "red";
$passverifycss = "red";
$passcheckbool = false;
$passcheckerror = "The passwords do not match<br />";
}else{
$passcheckbool = true;
$passverifycss = "normal";
$passcss = "normal";
}
}
//Check if all forums are correct
if ($fnamebool && $lnamebool && $emailbool && $passbool && $passverifybool && $passcheckbool == true)
{
echo "An Email has been sent to the site admin thank you.";
$body = "Hello $fname $lname\nthank you for signing up\nThe following information was submited\nFirst Name: $fname\nLast Name: $lname\nEmail: $email\nPassword: $pass";
mail($youremail, $subject, $body);
$to = $email;
$subject = "email from $youremail";
$body = "thank you for registering with us please email us at $youremail\n Reminder: \n password: $pass";
mail($to, $subject, $body);
}else{
echo $fnameerror;
echo $lnameerror;
echo $emailerror;
echo $passerror;
echo $passverifyerror;
echo $passcheckerror;
echo $emailsperror;
echo $emailaterror;
echo $emailpderror;
}
}
//end isset
?>
<hr width="100%">
<form action="index.php" method="post">
First Name:<br />
<input type="text" class="<?php echo $fnamecss; ?>" value="<?php echo $fname; ?>" name="fname" /><br />
Last Name:<br />
<input type="text" class="<?php echo $lnamecss; ?>" value="<?php echo $lname; ?>" name="lname" /><br />
Email:<br />
<input type="text" class="<?php echo $emailcss; ?>" value="<?php echo $email; ?>" name="email" /><br />
Password:<br />
<input type="password" class="<?php echo $passcss; ?>" value="<?php echo $pass; ?>" name="pass" /><br />
Verify Password<br />
<input type="password" class="<?php echo $passverifycss; ?>" value="<?php echo $passverify; ?>" name="passverify" /><br />
<input type="submit" value="Submit" name="submit" />
</form>
Marston
Holy CRAP! Next time use the 'Code' BBCode!
ocelotweb
Ok that looks fine and dandy and all, but how exactly do I put this to use? I tried putting it through notepad but to no avail. I've forgotten what little I know about PHP. I saved it as an html and a php file and nothing. I'm just more curious to see what your coding looks like....
raver
ocelotweb wrote:
Ok that looks fine and dandy and all, but how exactly do I put this to use? I tried putting it through notepad but to no avail. I've forgotten what little I know about PHP. I saved it as an html and a php file and nothing. I'm just more curious to see what your coding looks like....



well you have to save it in one .php and you must have apache running on your machine, you can save it as form.php and it must be placed in the htdocs folder in apache. After that just go to 127.0.0.1/form.php and watch it.
Next of, congratulations jcortes, this is probably the best form checking script that you can find on the web, seeing that almost all form checking tutorials are at a very low level, just for begginers. One thing i would like to add, two actually:
1)You should modify it to see if the pasword isn`t too small...like one or two characters, ussually it is best that the password should contain a minimum of 6 characters.
2)You should probably insert those dates in a mysql db, instead of just mailing them to the admin, and if this is the case then you should add some extra security to the script
And one more thing...try something like
if(ereg('[^A-Za-z]', $lname)){ //Only lower or upper case letters allowed.
echo " Please use only alphabets a to z as user name ";
to check that the user doesn`t inputs numbers or other caracters in the name tag, thus adding some more security. You can use this in the password field also, adding numbers also.
And one more thing, the action of the form should be commented to change to the name of the script, otherwise it will be redirected to your index...
Reply to topic    Frihost Forum Index -> Miscellaneous -> Tutorials

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.