jd2007 Posted July 18, 2007 Share Posted July 18, 2007 how do i check wheter a text box is empty or not ? Quote Link to comment Share on other sites More sharing options...
ShadowMetis Posted July 18, 2007 Share Posted July 18, 2007 if($_POST['textbox_name'] == "") { echo "This box is empty!"; } Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 18, 2007 Author Share Posted July 18, 2007 thanks a lot ! Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 18, 2007 Share Posted July 18, 2007 Remember to press 'Topic Solved!' when you've been helped. Another way to do this: <?php if (!$_POST['textbox_name']) { echo "This box is empty."; } Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted July 18, 2007 Share Posted July 18, 2007 The Best way is: <?php if (isset($_REQUEST["textbox"])) { echo "Thank You!"; } else { echo "Textbox was not filled in."; } ?> Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 18, 2007 Share Posted July 18, 2007 The Best way is: <?php if (isset($_REQUEST["textbox"])) { echo "Thank You!"; } else { echo "Textbox was not filled in."; } ?> Why, exactly, is that the best way? Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 18, 2007 Share Posted July 18, 2007 wrong - isset() is not as reliable. use the function MADE for empty strings and variable values: if (empty($_POST['textbox'])) { empty } else { not empty } it even makes more sense mnemonically. Quote Link to comment Share on other sites More sharing options...
rlindauer Posted July 18, 2007 Share Posted July 18, 2007 The Best way is: <?php if (isset($_REQUEST["textbox"])) { echo "Thank You!"; } else { echo "Textbox was not filled in."; } ?> How is that a best way? Generally, when you have a form that modifies anything you want to send it via post. According to Chris Shiflet: http://shiflett.org/articles/ideology I want to add a quick note about $_REQUEST before closing. Don't use it. $_REQUEST hides the source of data, much like register_globals. While it is slightly better in the sense that it is clearly input (whereas register_globals can make it difficult to distinguish between remote and local data), the difference between GET and POST data is significant. Consider the following excerpt from RFC 2616, the HTTP specification: In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested. If you can't distinguish between GET and POST, you cannot adhere to the specification. While this may seem like a harmless violation, there are also security concerns - particularly cross-site request forgeries. This is an attack that I've written about in php|architect before but never specifically in Security Corner. It is a likely topic for a future edition. edit: Sorry, way off topic and it's late Quote Link to comment 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.