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? Link to comment https://forums.phpfreaks.com/topic/101139-php-form-question/ 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? Link to comment https://forums.phpfreaks.com/topic/101139-php-form-question/#findComment-517250 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. Link to comment https://forums.phpfreaks.com/topic/101139-php-form-question/#findComment-517256 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. Link to comment https://forums.phpfreaks.com/topic/101139-php-form-question/#findComment-517258 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. Link to comment https://forums.phpfreaks.com/topic/101139-php-form-question/#findComment-517260 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!! Link to comment https://forums.phpfreaks.com/topic/101139-php-form-question/#findComment-517263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.