Checkbox in Form Helper Cake PHP

Here is the form helper that I used for the checkbox

<?php echo $this->Form->input('name',array('type'=>'checkbox','options'=>$options)); ?> 

and $ options:

  [options] => Array ( [58] => 58 [85] => 85 ) 

But I get only one checkbox with both values ​​in it. How can I check the box for each value.

+4
source share
3 answers

Use multiple attributes.

  echo $this->Form->input('Name',array( 'label' => __('Label',true), 'type' => 'select', 'multiple' => 'checkbox', 'options' => $options, )); 
+5
source

One more thing you should check, and this is really a general rule in cakephp when everything fails as expected. is an:

"Do you close the form correctly? Do your entries remain inside the <form>...</form> ? If you don’t know how to check, just use your preferred DevTool and check the HTML page displayed.

This is almost what I forgot to check mostly and which always allows me to spend a lot of time!

0
source

If you create the $ option variable in the view, this will help you:

 $options = array("key" => "value" , "key" => "value" , "key" => "value"); 

But if you install it on the controller, this will help you:

 $this->set('options', array("key" => "value" , "key" => "value" , "key" => "value")); 
  • Key
  • is the value in each input input option
  • Value is the text of parameter tags
0
source

Source: https://habr.com/ru/post/1500736/


All Articles