Hello, I am making a table that is a form where every item added has a checkbox and the form has 2 submit buttons, 1 is to edit e 1 to delete. _________________________________ __|______________________________ | Italy X | Us X | Canada __________________________________ | Edit | Delete |
The problem I am having is, since you can edit more than 1 item, I don't know how to correctly validate them on the process view. Here is the code to what I have done. function process() { if ( !empty($this->params['form']['del']) ){ $this->delete(); } else if ( !empty($this->params['form']['edit']) ){ $this->edit(); } else if ( !empty($this->params['form']['save']) ){ $this->save(); } } function save() { if(!empty($this->data)) { foreach($this->data as $country): if ($this->Country->save($country)) {} endforeach; $this->redirect('/countries'); $this->Session->setFlash('<span>Saved</ span>','default',null,'error'); } } function edit() { if (!empty($this->data)) { $i =0; foreach($this->data['Country'] as $id=>$value): if ($value == 1) { $this->Country->id = $id; $this->data['Country'.$i] = $this->Country->read(); $i++; } endforeach; if ($i == 0) { $this->Session->setFlash('<span>Nothing Selected</ span>','default',null,'error'); $this->redirect('/countries'); } $this->set('countries', $i); } } process.ctp <?php echo $form->create(array('url'=>'/countries/process')); ?> <?php for($i =0; $i<$countries; $i++) { ?> <?php echo $form->hidden('Country'.$i.'.Country.id'); ?> <?php echo $form->input('Country'.$i.'.Country.name')?> <?php } ?> <?php echo $form->submit('Save', array('name'=>'save')) ?> <?php echo $form->end(); ?> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---