962 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Ireland
  • Sold between 10 000 and 50 000 dollars
EireStudio says

Hey Guys,

I am storing the entire $_POST array in my options panel, but it stores the empty fields too (dynamically generated). How do I filter out the empty value and not include them?

This doesn’t work :(

<?php foreach($_POST['eirepanel_inline_ads_options_name'] as                                         $post_eirepanel_inline_ads_options_name):
if(empty($post_eirepanel_inline_ads_options_name)): 
echo 'empty';
else: 
update_option('eirepanel_inline_ads_options', $_POST);
$eirepanel_inline_ads_options = get_option('eirepanel_inline_ads_options');
endif; 
endforeach;
?>
271 posts The Dominant One
  • Elite Author
  • Won a Competition
  • Exclusive Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 3-4 years
  • Bought between 100 and 499 items
  • Referred between 50 and 99 users
wptitans says

if(trim($post_eirepanel_inline_ads_options_name)==""):
echo "empty";


This is how I do it :)

962 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Ireland
  • Sold between 10 000 and 50 000 dollars
EireStudio says

Thanks for the reply mate but I am storing the POST array so your solution would not work :(

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

Thanks for the reply mate but I am storing the POST array so your solution would not work :(

You should loop though the $_POST array and create a new array with the only values you need… make a print_r($_POST); to see how many things that you don’t need are in it.

25 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 250 000 and 1 000 000 dollars
feeleep says

I guess ‘empty’ will not work. Did you try ‘isset’ instead? If not working, comparing it with an empty string ( if( $_POST[ ‘var_name’ ] != ’’ ) ) should work.

147 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Sold between 250 000 and 1 000 000 dollars
FlexiPress says

@RedHenry,

It is not easy to give you the best direction if we can’t see the full code, we don’t know how you write your form elements…

If you are familiar with debugging, you can try ParkerAndKent’s suggestion, print_r($_POST); will output all arrays that will help you analyze your problem. you can also try to use print_r($_POST[‘eirepanel_inline_ads_options_name’]) and we can see the stored value…

you can also send your full code to me through my Profile page and i would love to check it ;)

by
by
by
by
by
by