al3x8730 Posted August 31, 2008 Share Posted August 31, 2008 I own http://imshare.us.to And I need help adding validation to the registration form. I'm willing to pay if need be. But if it's simple, I would appreciate the help. So if someone registers without a e-mail, password, etc... Make it reject, and tell the user what went wrong. Thanks. Link to comment https://forums.phpfreaks.com/topic/122123-adding-validation-to-a-form/ Share on other sites More sharing options...
Vermillion Posted August 31, 2008 Share Posted August 31, 2008 Well, there are many methods to do a validation system. Personally, I use custom class for that, but we can make a simple validation system without one: Suppose you have the following form: <form method="post" action=""> Username: <input type="text" name="username" /><br /> Password: <input type="password" name="pass" /><br /> Retype Password: <input type="password" name="pass2" /><br /> E-Mail: <input type="text" name="email" /> </form> Now you have this PHP Script: <?php $username = $_POST['username']; $pass = $_POST['pass']; $pass2 = $_POST['pass2']; $email = $_POST['email']; if(strlen($username) < 3){ // If the username has less than 3 characters, print an error message and leave the script after that. echo "Invalid username. It must have 3 characters or more."; return 0; } if(strlen($pass) < 6){ // If the password has less than 6 characters, print a error message and leave the script. echo "Your password must have 6 characters or more."; return 0; } if($pass != $pass2){ echo "The passwords did not match. Please try again."; return 0; } if(strlen($email) < 3){ // If the E-Mail has less than 3 scripts, print a message and leave the script. return 0; } if(!preg_replace("/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $email){ // If the E-Mail does not have a "@" or dot at the end, print a message and leave the script. echo "Invalid E-Mail"; return 0; //If there were no errors, you can put all your database stuff here. ?> Obviously, this was made quickly and it is not reliable. With that script I don't even check for user input so SQL injection is something very easy to do. So probably you can fix the script and make it better. There are also many things I don't like from this script, so I would post my method, but it only works well for my custom forum. I'm sure you can modifty that though. Link to comment https://forums.phpfreaks.com/topic/122123-adding-validation-to-a-form/#findComment-630525 Share on other sites More sharing options...
al3x8730 Posted August 31, 2008 Author Share Posted August 31, 2008 I have to go for a bit now, but later do you think it's possible that we talk talk on msn/aim or yahoo and you can help me setup my registration with validation? I'd really appreciate it, and as I said before, I can pay if needed. Link to comment https://forums.phpfreaks.com/topic/122123-adding-validation-to-a-form/#findComment-630529 Share on other sites More sharing options...
Vermillion Posted August 31, 2008 Share Posted August 31, 2008 Sure. My MSN is [email protected] I don't think you can pay me for a number of factors, starting on my age ... But I'm sure we can find something small you can do for me. Link to comment https://forums.phpfreaks.com/topic/122123-adding-validation-to-a-form/#findComment-630530 Share on other sites More sharing options...
al3x8730 Posted August 31, 2008 Author Share Posted August 31, 2008 I'm about to run out now, but I added you. Add me, [email protected] Link to comment https://forums.phpfreaks.com/topic/122123-adding-validation-to-a-form/#findComment-630531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.