phprocker Posted November 14, 2010 Share Posted November 14, 2010 Hey all. I have a form with inputs "menuitem[]" array. Upon no user input to one of these fields I want to set a variable error and include the form generation page. Is my following code a feasible way to do this? foreach($_POST['menuitem'] as $value) { if(!isset($value) || $value == "") { $emptyvalue = TRUE; } } if ($emptyvalue) { $erroralert = "You must fill in all the form fields! Please try again!"; include "views/addmenus.php"; exit(); } If works but just a bit unsure about it. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/218624-redirectingincluding-if-array-value-not-set/ Share on other sites More sharing options...
kratsg Posted November 14, 2010 Share Posted November 14, 2010 If you know it is the form of an array, might as well use the empty() function. - http://us3.php.net/empty - if(empty($_POST['menuitem']) && is_array($_POST['menuitem'])) Quote Link to comment https://forums.phpfreaks.com/topic/218624-redirectingincluding-if-array-value-not-set/#findComment-1134033 Share on other sites More sharing options...
phprocker Posted November 14, 2010 Author Share Posted November 14, 2010 That works to check if the array is there, but I'm talking about individual array values. My code works I just wanted an experts opinion on the method I used and if there is a better way to achieve it. Quote Link to comment https://forums.phpfreaks.com/topic/218624-redirectingincluding-if-array-value-not-set/#findComment-1134118 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.