PHP checkbox data to table?

I have a list of names that I need to implement in "checkboxes", and I need to insert the names that are marked into the table in SQL via CakePHP. Someone suggested using:

$this->Form->input('Members', array('multiple' => 'checkbox'));

I'm not sure what he is doing.

+5
source share
1 answer

Here I will just show you how to save the values โ€‹โ€‹of several checkboxes. //add.ctp, for example

 <em>How would you describe your job (mark as many as applies): </em> <?php $options = array( 'Physical' => 'Physical', 'Mental' => 'Mental', 'Stressful' => 'Stressful', 'Easy-going' => 'Easy-going', 'Secure' => 'Secure', 'Non-secure' => 'Non-secure', 'Exhausting' => 'Exhausting', 'Relaxing' => 'Relaxing' ); echo $this->Form->input('describeJob', array('label' => false, 'div' => false, 'type' => 'select', 'multiple'=>'checkbox', 'legend' => 'false', 'options' => $options )); ?> 

// In the controller

 public function somthing() { if (!empty($this->data)) { $this->data['Model']['describeJob'] = implode(",",$this->data['Model']['describeJob']); $this->Model->create(); $this->Model->set($this->data); $this->Model->save(); } } 

I hope this helps you.

+2
source

All Articles