TimUSA Posted April 15, 2008 Share Posted April 15, 2008 I have a PHP question probably easy but no for me. I am developing an online employment application for my company and i want to require the user to post at least one employment reference. so i have for example $_POST['emp1'] , $_POST['emp1add'] , $_POST['emp1phone'] ect ect ect. Instead of checking each field individually can I do something like this? if (empty($_POST['emp1*'])) { execute code } If not any suggestions? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 15, 2008 Share Posted April 15, 2008 Each of those fields has different verification needs, so why would you lump them all together? Quote Link to comment Share on other sites More sharing options...
TimUSA Posted April 15, 2008 Author Share Posted April 15, 2008 Yes but first I want to check if they are empty. Quote Link to comment Share on other sites More sharing options...
AP81 Posted April 15, 2008 Share Posted April 15, 2008 You can do something like this: <?php foreach ($_POST as $key => $value) { if (!empty($value)) { //do something } } ?> However I'd advise against it. It is much better to do individual validation for each posted item. Quote Link to comment Share on other sites More sharing options...
benphp Posted April 15, 2008 Share Posted April 15, 2008 I'd use javascript to validate the form. Quote Link to comment Share on other sites More sharing options...
TimUSA Posted April 15, 2008 Author Share Posted April 15, 2008 in the long run i will have probably ended up agreeing with you, so i will go ahead and agree with you now! especially after reading this thread...wow what an idiot! http://www.phpfreaks.com/forums/index.php/topic,192347.0.html Ben: problem is i barely know php, would know where to begin with js!! 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.