Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set checkbox to checked in CakePhp

    • 0
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.24k
    Comment on it

    Hi All,

    In this blog we will discuss about how to set checkbox checked in cakePhp application.

    You should set the checkbox checked/selected with the 'selected' option.

    For example-

    You can find a list of categories from the database table called Category as shown below:

    $catLists= $this->Category->find('list', array(
      'fields' => array('id')
    ));
    
    $selectedCats= array(1,2,3);//this represents what all categories you want to be checked
    

    Now you have to set all these values to the checkbox in cakephp's conventions

    echo $this->Form->input('User.category', array(
        'label' => 'Categories',
        'type' => 'select',
        'multiple' => 'checkbox',
        'options' => $catlists,//you can set the variable as shown in above example in  here
        'selected' => $selectedCats//you can write in the list of the id's as defined in above example ,which  will automatically display checkbox as selected with id's 1,2,3.
      ));
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: