stelthius Posted December 18, 2008 Share Posted December 18, 2008 Hello again guys I'm trying to force the username field in my registration form to all lowercase so the users cant register a name with uppercase in it e.g. TesterAccount So far i have tried using CSS which didnt work text-transform: lowercase; text-transform: uppercase; text-transform: capitalize; So then i tried using PHP's way of doing it strtolower but i cant seem to get it to work below is my registration form firleds, <? if($form->num_errors > 0){ echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>"; } ?> <form action="process.php" method="POST" enctype="multipart/form-data"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" id="username" name="user" onchange="toggle_username('username');" maxlength="30" value="<? echo $form->value("user"); ?>"> </td><td><div id="username_exists"></div></td></tr></td><td><? echo $form->error("user"); ?></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" id="pass" onChange="toggle_pass('pass')" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?><div id="password_strength"> </div> <tr><td>Confirm Password :</td><td><input type="password" name="pass2" id="pass2" maxlength="30" value="<? echo $form->value("pass2"); ?>"></td><td><? echo $form->error("pass2"); ?></td></tr> <tr><td>Email:</td><td><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>"></td><td><? echo $form->error("email"); ?></td></tr> <td>Avatar:<input type="file" name="avatar"><? echo $form->error("avatar"); ?></td> <tr><td> <img src="CaptchaSecurityImages.php" /><br /> <label for="security_code">Security Code: </label> <input id="security_code" name="security_code" type="text" /><br /> <? echo $form->error("security_code"); ?> </td></tr> <tr><td colspan="2" align="right"> <input type="hidden" name="subjoin" value="1"> <input type="submit" value="Join!"></td></tr> <tr><td colspan="2" align="left"><a href="index.php">Back to Main</a></td></tr> </table> Any tips or ideas are great thanks guys again Rick Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/ Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 Why not just strtolower it automatically when inserted into the DB...that is what I do. If you want it done on the page, look into JavaScript to do it. Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718708 Share on other sites More sharing options...
stelthius Posted December 18, 2008 Author Share Posted December 18, 2008 I tried to but i never succeeded, im relativly new to php and i tried what i assumed would work. i added it to my register function function procRegister(){ global $session, $form; if(ALL_LOWERCASE){ $_POST['user'] = strtolower($_POST['user']); And i really dont want to be using javascript to do it. Rick Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718712 Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 I would not use javascript either, but the above looks fine to me...is not actually going to lowercase? I guess what I am trying to say is, it does not matter how it looks on the form as long as you use strtolower before you insert it into the DB. But just an FYI, if when validating a user for logging in, if you check the data via the database instead of PHP it is case insensitive. So yea it really should not matter if it is lower or upper, at least in my opinion =) Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718716 Share on other sites More sharing options...
stelthius Posted December 18, 2008 Author Share Posted December 18, 2008 Well what i tried isnt registering the user in all lower case so im kinda stumped here as i really do want to do it in PHP before it goes into the DB Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718719 Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 Post more code so I can see where you are going wrong. Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718721 Share on other sites More sharing options...
stelthius Posted December 18, 2008 Author Share Posted December 18, 2008 Ok here are my registration parts, This processes the registration : function procRegister(){ global $session, $form; if(ALL_LOWERCASE){ $_POST['user'] = strtolower($_POST['user']); } $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['pass2'], $_POST['email'], $_FILES['avatar']['name'], $_FILES['avatar']['size'], $_FILES['avatar']['type'], $_FILES['avatar']['tmp_name'], $_POST['security_code']); if($retval == 0){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = true; header("Location: ".$session->referrer); } else if($retval == 1){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } else if($retval == 2){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = false; header("Location: ".$session->referrer); } } And this is what checks if the name is banned etc etc etc function register($subuser, $subpass, $subpass2, $subemail, $avatar_name, $avatar_size, $avatar_type, $avatar_tmpname, $subsecurity_code){ global $database, $form, $mailer; //The database, form and mailer object /* Username error checking */ $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered"); } else{ /* Spruce up username, check length */ $subuser = stripslashes($subuser); if(strlen($subuser) < 5){ $form->setError($field, "* Username below 5 characters"); } else if(strlen($subuser) > 30){ $form->setError($field, "* Username above 30 characters"); } /* Check if username is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", $subuser)){ $form->setError($field, "* Username not alphanumeric"); } /* Check if username is reserved */ else if(strcasecmp($subuser, GUEST_NAME) == 0){ $form->setError($field, "* Username reserved word"); } /* Check if username is already in use */ else if($database->usernameTaken($subuser)){ $form->setError($field, "* Username already in use"); } /* Check if username is banned */ else if($database->usernameBanned($subuser)){ $form->setError($field, "* Username banned"); } } /* Password error checking */ $field = "pass"; //Use field name for password if(!$subpass){ $form->setError($field, "* Password not entered"); } else{ /* Spruce up password and check length*/ $subpass = stripslashes($subpass); if(strlen($subpass) < 4){ $form->setError($field, "* Password too short"); } /* Check if password is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){ $form->setError($field, "* Password not alphanumeric"); } } /* Password2 error checking */ $field = "pass"; //Use field name for password $field2 = "pass2"; // Second field for password if(!$subpass2){ $form->setError($field2, "* Password not entered"); } else{ //$subpass = stripslashes($subpass); //$subpass2 = stripslashes($subpass2); if($subpass!==$subpass2){ $form->setError($field2, "* Passwords does not match"); } } To be honest thats the only two pices of code i can think of that would stop it form going to all lower case, Rick Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718725 Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 But that is really not what I am after, Where does the data get inserted into the database? Also you send them to "session->register" but no where in that register function are you setting the variables to session data....or even updating the $_POST data...that just confuses me... Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718734 Share on other sites More sharing options...
stelthius Posted December 18, 2008 Author Share Posted December 18, 2008 sorry i fgot to paste that part, sorry, /* No errors, add the new account to the */ else{ if($database->addNewUser($subuser, md5($subpass), md5($subpass2), $subemail, $avatar_name)){ if(EMAIL_WELCOME){ $mailer->sendWelcome($subuser,$subemail,$subpass); } /*** This is new ************************/ if(AUTO_LOGIN){ /* Username and password correct, register session variables */ $this->userinfo = $database->getUserInfo($subuser); $this->username = $_SESSION['username'] = $this->userinfo['username']; $this->userid = $_SESSION['userid'] = $this->generateRandID(); $this->userlevel = $this->userinfo['userlevel']; /* Insert userid into database and update active users table */ $database->updateUserField($this->username, "userid", $this->userid); $database->addActiveUser($this->username, $this->time); $database->removeActiveGuest($_SERVER['REMOTE_ADDR']); } return 0; //New user added succesfully }else{ return 2; //Registration attempt failed } } } Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718735 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 if(ALL_LOWERCASE){ $_POST['user'] = strtolower($_POST['user']); } What are you expecting this to do? It reads: if the constant ALL_LOWERCASE exists, make that variable lowercase. Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718747 Share on other sites More sharing options...
stelthius Posted December 18, 2008 Author Share Posted December 18, 2008 Ok point and laugh at the idiot, lol that fixed it thanks for noticing the obvious Crayon lol Rick Quote Link to comment https://forums.phpfreaks.com/topic/137529-solved-forcing-lowercase-in-register-form/#findComment-718750 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.