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; ?>"> <? } ?> 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 } } ?> 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 } } } } ?> 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 } } ?> 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
Archived
This topic is now archived and is closed to further replies.