helraizer Posted February 4, 2008 Share Posted February 4, 2008 Hi folks, I have this site and idea http://www.helraizer.co.uk/mychatbox/ at the moment I'm using javascript to alert the user if they haven't entered a username or message but all this does is popup an alert message and return false. However, if their browser does not support javascript (javascript is turned off) then it just won't send and will give them no reason why. How would I get it so that, using php, if the submit button is pressed and either the username is less than 3 characters and/or the comment field is less than 5 characters then above the image (on the site page) a list of errors would appear. So if nothing was wrong it shows no errors but if the user name was less than 3 characters and comment <5 it'd appear "Error! -Your username is too short, please enter a user name between 3 and 10 characters. -Your comment is too short, please enter a comment between 5 and 75 characters." (or similar) How would I do this? I know this is a "help" forum not a "do it for me forum" but if you guys can give me a baseline for this problem, to work with from there I can probably get it from there. Thanks, Sam Quote Link to comment https://forums.phpfreaks.com/topic/89283-alert-user-of-errormissing-data-in-form/ Share on other sites More sharing options...
ratcateme Posted February 4, 2008 Share Posted February 4, 2008 you could add a check like this in your php code to check for emtpy fields <?php if($_GET['username']!='' && strlen($_GET['username'])>3 && $_GET['input'] && strlen($_GET['input'])>5){ //update message board }else{ //put a message out saying form filled incorect } ?> Scott. Quote Link to comment https://forums.phpfreaks.com/topic/89283-alert-user-of-errormissing-data-in-form/#findComment-457187 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 for that to happen the form has to be submitted, and then the fields will empty. php is server-side, has to be submitted to check on things. stay with javascript. Quote Link to comment https://forums.phpfreaks.com/topic/89283-alert-user-of-errormissing-data-in-form/#findComment-457199 Share on other sites More sharing options...
haku Posted February 4, 2008 Share Posted February 4, 2008 Sorry, but you would be best off ignoring the previous poster for the reasons you stated in your first post - if the user has javascript turned off this will not work. Your best bet is to do what you are thinking of, and create a php solution, then overlay a javascript solution as a supplement to the php. I basically do what ratcateme does. I check for the different requirements of the field, and if they aren't met, I store an error message into an array I call $errors. After checking for all the fields, I check to see if $errors[0] is null (i.e. no errors in the form). If its null, then I proceed with processing the error. If its not null (i.e. errors were found in the form input), then I use a loop to output each of the errors stored in $errors, followed by the form itself so they can re-submit the information. Good luck! Try some script out and post it here if you are having some troubles. Quote Link to comment https://forums.phpfreaks.com/topic/89283-alert-user-of-errormissing-data-in-form/#findComment-457238 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.