Jump to content

[SOLVED] Using a foreach while removing empty post values..


jaxdevil

Recommended Posts

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; ?>">
<?
}
?>

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
		}
	}
    }
}
?>

<?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
    }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.