5

I have a name list which i need to implement in "checkboxes" and I need to insert those names that are checked, into a table, in SQL through CakePHP. Someone suggested to use:

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

I am not sure what it does.

Disorder
  • 430
  • 1
  • 6
  • 16
  • 1
    is it just a list in a string you want to save, or is it a list of HABTM associations that you want to save? – Colonel Mustard Jun 23 '15 at 08:59
  • Please state the version of CakePHP you are using. There are significant differences. – drmonkeyninja Jun 23 '15 at 10:13
  • I am using 2.x version of cakephp. The list i have is from a column of a different table and i need to save those that are check marked into a column of a new table – Disorder Jun 30 '15 at 09:11

1 Answers1

2

Here I just give a demonstrate to you how to save values of multiple check-box. //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 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 that will be help you.

Supravat Mondal
  • 2,574
  • 2
  • 22
  • 33