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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.