1

I am using a script that has a foreach loop and this shows the right amount of checkboxes depending on what is set in the admin area of Magento.

The problem that I am facing is that there may be multiple checkboxes however only the checkbox that is selected nearest the top is the value that is sent with the form. I need all the checkbox values that have been selected to be sent.

This is what I have in my mail script to get the checkboxes values $check = $_POST['check'];

And this is the code below that uses the foreach to show the right amount of checkboxes.

 <?php
    $SKU = "1282670_01";
    $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$SKU);
    if($product->getTypeId() == "configurable"){  
        $childs = $product->getTypeInstance()->getUsedProducts();  
    }
    $i = 0;
    foreach ($childs as $child) { ?>
    <?php $colour_name =  $child->getAttributeText('real_colour'); ?>
    <li class="notranslate focused" id="fo143li2">
    <fieldset>
    <div>
    <span>

    <img width="35" height="35" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $child->getSwatch() ?>">
    <input type="checkbox" style="margin-top:-10px;" onchange="handleInput(this);" tabindex="5" value="<?php echo $colour_name ?>" class="field checkbox" name="check" id="<?php echo $colour_name ?>">
    <label for="<?php echo $colour_name ?>" class="choice"></label>
4

2 回答 2

2

$_POST您所有的复选框都具有相同的名称,因此您的数组中只会出现一个。更改代码以使用唯一名称,或使用数组形式,即name="check[]"

于 2013-06-21T16:59:10.317 回答
0

您只允许一个输入提交其名称值(在单选按钮的情况下,它使用“on”中的任何一个),但是您可以通过将名称更改为check[]. 每个check[]将组合成一个数组并提交为name => ['value1', 'value2', 'value3']

同样,您可以使用键而不是推到数组的末尾,就像 name="check[<?php echo $colour_name ?>]" value="true"PHP 会将其显示为array('red' => 'true', 'blue' => 'true').

于 2013-06-21T17:05:57.577 回答