I am using Magento community and I have below problem. I have created a module which adds a product to customer groups. I have added checkboxes for all the customer groups in a tab using Ajax tab using code..

<?php foreach ($group as $eachGroup) { ?>
<input type="checkbox" name="productgroup[]" value="<?php echo $eachGroup->getCustomerGroupId(); ?>" <?php if(in_array($eachGroup->getCustomerGroupId(),$existGroupProduct)){ ?> checked="checked" <?php } ?>>
<?php } ?>

When I select a customer group, it saves the data. When I edit my selected values it works fine.

Now when I try to remove all the groups by unselecting all checkboxes, it is not working. I have checked my variable using below conditions but none works.


If I set the value of the array as null in my function it also resets my customer groups value if I have not opened my "Customer Group" tab and I save the product.


Try bellow code

if(isset($_POST['productgroup']) && is_array($_POST['productgroup'])) {
    $_POST['productgroup'] = $_POST['productgroup'];
}else {
    $_POST['productgroup'] = array();
| improve this answer | |
  • Hi @Abdul, My question is the variable, "productgroup" is not being passed as null to POST data when I unselect all checkboxes. I think it should passed as ['productgroup']=>Array(), but its not. – John Jan 18 '16 at 9:21
  • yes it is not pass if your unselect all checkboxes – Abdul Jan 18 '16 at 9:22
  • And if I don't go to my tab and save the product, it also does not pass to POST data, again resetting my data, which is wrong. – John Jan 18 '16 at 9:23
  • if your try echo '<pre>'; print_r($_POST); – Abdul Jan 18 '16 at 9:23
  • If your not selected checkboxe & radio button then your data is not post – Abdul Jan 18 '16 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.