Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Default checked the checkboxes in CakePHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 647
    Comment on it

    Hi Reader's,
    Welcome to FindNerd,today we are going to discuss to default checked the checkboxes in CakePHP 3
    If we want to set checkbox in our cakephp application for showing list of a product in checkbox then firstly we have to find a list of products from our database.

    for example

    suppose there is a table name is "product" and we want to find all products then our query will like below
     

    <?php
    
      //prodLists is a varibale
      $prodLists= $this->product->find('list', array(
        'fields' => array('id')
      ));
    
    ?>

    Now let set product for checked

    $selectedProducts= array(1,2,3);

    It represents what all Products you want to be checked. In above example 1,2,3 is id's.
    Now we have to set all these values to the checkbox.
    you can see below code:

    <?php
    
    echo $this->Form->input('User.product', array(
        'label' => 'Productlist',
        'type' => 'select',
        'multiple' => 'checkbox',
        'options' => $prodlists,//you can set the variable as shown in above example 
        'selected' => $selectedProducts
      ));
    
    ?>
    

    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: