checkbox - multiple checkboxes with cakephp 1.2 -
i have page list of books, , every row has checkbox. (i'm using cakephp 1.2). want allow user save multiple books. have checkbox in view (in cycle, list of books):
<?php echo $form->input('salva', array('value' => $cdbiblio['cdbiblio']['codicebiblio'], 'label' => '', 'type' => 'checkbox')); ?> this form:<?php echo $form->create('cd_biblios', array('action' => 'save')); ?> and button:
<?php echo $form->end('add all');?> in controller, have debugging:
debug($this->data); foreach($this->data['cd_biblios']['salva'] $item) { debug($item); } but it's not working. noticed takes lastly book id of list debug($this->data); , if check more 1 book, show 0 or lastly book id, example:
array ( [cd_biblios] => array ( [salva] => 0 ) ) solved: in view utilize danial's code. in controller utilize code:
if(!empty($this->data)) { $item=$this->data; debug($item); $dim=count($item['model']['field']); $i=0; ($i=0;$i<$dim;$i++) if ($item['model']['field'][$i]!=0) { $data = $this->session->read('libri'); $data[] = $item['model']['field'][$i]; $this->session->write('libri', $data); } $this->session->setflash(__('i libri sono stati salvati', true)); $this->redirect($this->referer()); }
in view:
<?php foreach($array $each_elem) { echo $form->checkbox( 'model.field', array( 'id'=>'abcd_'.$each_elem['model']['id'], 'value' => $each_elem['model']['id'], 'hiddenfield' => false, 'name' => 'data[model][field][]', 'label' => false, 'div' => false, )); } ?> on submit form, checked values in controller in $this->request->data
cakephp checkbox cakephp-1.2
No comments:
Post a Comment