unsider Posted July 19, 2008 Share Posted July 19, 2008 I've recently resolved a past issue with the input, but now validating if it is set with PHP is the problem. While I ultimately will validate it both client side and serve side my main objective is validating with PHP atm. I've been able to validate all other form types, but not <select> forms. I can choose any value from 1-4 and have it input the correct id number, but if I leave it set to "-1" it inputs the 0 default, and it should be returning an error. All simply validation, I'm not having any errors inputting. Here's my form <select name="cat"> <option value="-1" selected="selected"> </option> <option value="1">test</option> <option value="2">testi</option> <option value="3">testin</option> <option value="4">testing</option> </select> I'm using a quick test below to validate it's existence. if(!isset($_POST['cat'])) { echo "not set"; exit(); } But unfortunately this does not catch anything as it inputs a default value of 0 into the DB field. Which by the way is: cat_id, int, 11, NULL: NO, default: 0 Are there any other methods of validating if the select field selection is not set on the "-1" option. Or another method of doing this? This is really frustrating me, as this should be one of the most simple operations, but I just can't resolve it. Anything, PLEASE i really need to solve this problem. Tutorials, code, code you've used in the past. ANYTHING. ??? Quote Link to comment https://forums.phpfreaks.com/topic/115563-solved-ltselectgt-form-validation-php-need-help/ Share on other sites More sharing options...
vikramjeet.singla Posted July 19, 2008 Share Posted July 19, 2008 you may try this: <select name="cat"> <option value="">Select Any</option> <option value="1">test</option> <option value="2">testi</option> <option value="3">testin</option> <option value="4">testing</option> </select> <?php if(isset($_POST['cat']) && empty($_POST['cat'])) { echo "not set"; exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115563-solved-ltselectgt-form-validation-php-need-help/#findComment-594109 Share on other sites More sharing options...
unsider Posted July 19, 2008 Author Share Posted July 19, 2008 you may try this: <select name="cat"> <option value="">Select Any</option> <option value="1">test</option> <option value="2">testi</option> <option value="3">testin</option> <option value="4">testing</option> </select> <?php if(isset($_POST['cat']) && empty($_POST['cat'])) { echo "not set"; exit(); } ?> Unfortunately this did not work either. Went right by it. Quote Link to comment https://forums.phpfreaks.com/topic/115563-solved-ltselectgt-form-validation-php-need-help/#findComment-594114 Share on other sites More sharing options...
wildteen88 Posted July 19, 2008 Share Posted July 19, 2008 Check that $_POST['cat'] holds a number greater than 0: <?php if(isset($_POST['cat']) && $_POST['cat'] < 1) { echo "not set"; exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115563-solved-ltselectgt-form-validation-php-need-help/#findComment-594126 Share on other sites More sharing options...
unsider Posted July 19, 2008 Author Share Posted July 19, 2008 Thank you wildteen, it worked with a little tweaking. Quote Link to comment https://forums.phpfreaks.com/topic/115563-solved-ltselectgt-form-validation-php-need-help/#findComment-594131 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.