jaxdevil Posted October 30, 2008 Share Posted October 30, 2008 here is the code I am using. How can I modify this to NOT create entries for posted form variables that contained no data? i.e. where ( whatever == '' ) <? foreach ($_POST as $key => $value) { ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130775-solved-using-a-foreach-while-removing-empty-post-values/ Share on other sites More sharing options...
wildteen88 Posted October 30, 2008 Share Posted October 30, 2008 <?php foreach ($_POST as $key => $value) { if(!empty($value)) { ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130775-solved-using-a-foreach-while-removing-empty-post-values/#findComment-678717 Share on other sites More sharing options...
jaxdevil Posted October 30, 2008 Author Share Posted October 30, 2008 Perfection! Thanks man! I added some more parts to it, as I have some fields that come up as 0.00 and $0.00 so I wanted those gone too. I modified what you posted slightly. Thanks a ton! <?php foreach ($_POST as $key => $value) { if(!empty($value)) if ($value != '$0.00') { if ($value != '0.00') { { ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"> <?php } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130775-solved-using-a-foreach-while-removing-empty-post-values/#findComment-678720 Share on other sites More sharing options...
wildteen88 Posted October 30, 2008 Share Posted October 30, 2008 <?php foreach ($_POST as $key => $value) { if(!empty($value) && ( trim($value,'$') != '0.00') ) { ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130775-solved-using-a-foreach-while-removing-empty-post-values/#findComment-678724 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.