Jump to content

Multiple checkbox - some options checked by default


mipetala

Recommended Posts

Hi!

 

I want to have some elements checked by default depending on the value in database.

 

My problem is that if one element of the array gets checked then all the other elements become also checked.

 

For example:

 

$checkbox = new Zend_Form_Element_MultiCheckbox(self::SELECT, array('Decorators'=>array('ViewHelper', 'Errors', 'Label', array('HtmlTag', array('tag'=>'div', 'class'=>'select_surveillance')))) ) ;	

foreach($this->_accountListGroups  as $i => $value)
{		
   if($value->getSurveillance())
           {
     $checkbox->addMultiOption($i , value->getDisplayName())->setAttrib("checked", "checked");
   }			
$checkbox->addMultiOption($i , $value->getDisplayName());							
      }

 

Although I have just one $value->getSurveillance() ==  true, I get the following result:

 

<div class="select_surveillance">
<label for="select-3"><input type="checkbox" name="select[]" id="select-3" value="3" checked="checked" />Customer1 gw140</label><br />

<label for="select-8"><input type="checkbox" name="select[]" id="select-8" value="8" checked="checked" />Customer1 gw70</label><br />

<label for="select-4"><input type="checkbox" name="select[]" id="select-4" value="4" checked="checked" />Customer2 gw140</label><br />

<label for="select-5"><input type="checkbox" name="select[]" id="select-5" value="5" checked="checked" />Customer3 gw140</label>
</div>

 

Does anyone know another way to check some of my checkboxes?

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.