mooeypoo Posted January 6, 2008 Posted January 6, 2008 Hey guys, I'm writing a registration page in PHP again, and I was thinking of adding an option to "Check if Username is available". I want the registration process to be as userfriendly as possible, so sending the person out of the page (as in - using php routines to do that) and then telling him the username already exists is a pain for the user, or a serious pain for me (i will need to store his pre-supplied fields and return them again to the registration page so he doesn't have to type 'em all again.. pain!) So.. is there a way of making a little "check if user exists" pane? I was thinking perhaps an iframe with access to php script.. but i'm not sure if that works in all browsers. Also.. I'm not sure how I can transfer the details of the textbox "regUsername" to the iframe to use in PHP... and update it when the user is typing a new username (or clicking the button "recheck availability" or something)... Any ideas? thanks! ~moo
Cap'n Refsmmat Posted January 6, 2008 Posted January 6, 2008 AJAX. It doesn't use an iframe, but instead sends a query to the server, which responds with some data that your JavaScript can parse and do stuff with. A tutorial: http://www.w3schools.com/ajax/ajax_intro.asp
mooeypoo Posted January 6, 2008 Author Posted January 6, 2008 Yeah I'm looking into that, Thanks for the link Cap'n I did solve htis another way. Check this out: Registration Page: <input name="regUsername" type="text" style="width:120px;" /> <input type=button style="color:#003333; font-size:80%; font-weight: bold; margin-left: 8px;" OnClick='window.open("chkuseravailability.php?username="+RegistrationForm.regUsername.value,"WUserAvailability","width=200,height=70,toolbar=0,status=0,scrollbars=0,location=0,menubar=0,directories=0,resizable=0,left=200,top=200")' value="Check Availability"> page: chkuseravailability.php <?php session_start(); include("dbcon.php"); #DB Connection include("funcs.php"); #System Functions ##### CHECK IF USERNAME EXISTS IN THE DB: #### ## Running some anti-SQL injection routines and regex to check if the username is legal (alphanumeric, no quotes, etc). ?> <html><body> <?php #this section checks if username is legal, and if it does not appear in DB (php functions as usual). #IF TRUE (doesnt exist): ?> <font color="#006633"><b>Username is available!</b></font> <?php #IF FALSE (exists): ?> <font color="#990000"><b>This username already exists.<br />Please choose another.</b></font> <?php #END IF ?> </body></html> The result is a button next to the username textbox. When a user clicks it, a small window pops up with either "Available" or "Not Available", or with a custom error message in case the username is illegal. That solved my problem without getting into AJAX. I'm intending to anyways but for now, as I am not too well versed in AJAX, I guess that fixes my problem. Thanks ~moo
Cap'n Refsmmat Posted January 6, 2008 Posted January 6, 2008 That's a good way of doing it, although the XHTML gods are frowning on you for using <font>.
mooeypoo Posted January 6, 2008 Author Posted January 6, 2008 That's a good way of doing it, although the XHTML gods are frowning on you for using <font>. What am I missing? Why? I'm using CSS for the rest of the page, but for this tiny little window (which doesn't fit the rest of my usual CSS styling) I just picked that for the one-liner output.. Why is it bad to use <font> in XHTML though? Isn't it supported in all browsers (unlike "<div>" and "<span>") ?
Cap'n Refsmmat Posted January 6, 2008 Posted January 6, 2008 Div and span are supported in all modern browsers, and font is deprecated. I can understand it for a one-liner window, but I'm still an XHTML nitpicker.
mooeypoo Posted January 6, 2008 Author Posted January 6, 2008 Well I took it into advisement, thankyou Actually, I'm building the technical system and another guy is building the style - when he's done, we will migrate to his CSS and XHTML settings anyways, so this is temporary anyways (I don't even know what class names he'll use.. I'm just mainly concentrating on doing proper coding for the backend right now). But point taken ~moo
Cap'n Refsmmat Posted January 7, 2008 Posted January 7, 2008 That's always a good method of running things. I know I'm pretty pathetic at design (I'm great at syntax and the rules but I'm not creative at all) but fairly decent with the programming work.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now