diode Posted November 9, 2006 Share Posted November 9, 2006 Hello and how are you?I have searched the phpfaq and other places, and seem to remain confused. What I am trying to do is create a simple registration page for a small message board. Currently, I am using the html <form> tags. But I don't know how to check for NULL fields such as password, account name, etc. if I use a form, because there aren't any variables in there. The closest thing to variables that I can see is the name:<input type="text" name="firstname" />And with this, I am not sure how to do an if-then-else, since 'firstname' doesn't begin with '$'. Basically, if someone forgets to fill out a field, I want my webpage to prompt them telling them that they left out a field, and to fill it in, and when all fields are completed, the page goes on to the verification page to make sure their information is correct.Please excuse my catastrophic ignorance. Thanks :),diode Link to comment https://forums.phpfreaks.com/topic/26761-how-do-you-check-for-null-fields-in-registration-pages/ Share on other sites More sharing options...
brendandonhue Posted November 10, 2006 Share Posted November 10, 2006 You can use $_REQUEST['firstname'] to get the value of a form field called firstname. Link to comment https://forums.phpfreaks.com/topic/26761-how-do-you-check-for-null-fields-in-registration-pages/#findComment-122380 Share on other sites More sharing options...
realjumper Posted November 10, 2006 Share Posted November 10, 2006 You *could* do server side (with php) if you want, but then it is one more action that the server must perform. There is nothing wrong with doing that, but to save the extra work on the server side, why not do it on the client side with javascript? http://developer.apple.com/internet/webcontent/validation.html Link to comment https://forums.phpfreaks.com/topic/26761-how-do-you-check-for-null-fields-in-registration-pages/#findComment-122390 Share on other sites More sharing options...
roopurt18 Posted November 10, 2006 Share Posted November 10, 2006 You should never, ever, not in a million years, rely on javascript as your [i]only[/i] form validation enforcement.Why? Because it can be turned off by the user. If you only use javascript to validate your forms, any malicious user can just turn off javascript and submit any old data they want to.You must always, forever, and every single time, validate form data on the server. It is much more difficult for a malicious user to bypass this sort of form validation than just changing a browser setting.You can use javascript validation as a convenience feature to prevent your user from having to submit the form and wait for the server to validate it to fix a field, however.As for your specific problem, use the [b]method="post"[/b] when creating your HTML form and in the validation routine check the values in $_POST. If you have a form text field named "username", it will show up in $_POST['username']. You can do something like this:[code]if(isset($_POST['username']) && strlen(trim($_POST['username']))){ // A user name was entered!}else{ // You must enter a user name!}[/code] Link to comment https://forums.phpfreaks.com/topic/26761-how-do-you-check-for-null-fields-in-registration-pages/#findComment-122434 Share on other sites More sharing options...
realjumper Posted November 10, 2006 Share Posted November 10, 2006 Sorry roopurt, I don't agree...in this instance. The OP isn't protecting Fort Knox with his application. Any mesage board as the OP is developing is going to get hit with all sorts of troll type users irrespective of the validation method employed, and it will be up to a moderator to manually sort that out. I user server side validation where necessary, but (imo) it isn't warrented in this case and is just a waste of server resources....for the other 999,999 years you may have a point!! Link to comment https://forums.phpfreaks.com/topic/26761-how-do-you-check-for-null-fields-in-registration-pages/#findComment-122440 Share on other sites More sharing options...
brendandonhue Posted November 10, 2006 Share Posted November 10, 2006 Did you read his first post? Client-side validation would allow users to register with blank passwords and usernames. Link to comment https://forums.phpfreaks.com/topic/26761-how-do-you-check-for-null-fields-in-registration-pages/#findComment-122462 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.