1

i have a table named group where i have columns like admin,editor,user,guest they are all boolean.
i want to create a group using checkbox. so in my view i got checkbox like admin,editor,user,guest and a create button. When i click the create button i want the checked options to be true in database and unchecked remains false. how can i do that?

I am new in codeigniter.

<html>
<head>
    <title>Create A group</title>
</head>
<body>
    <?php echo form_open('group/create_group'); ?>
    <div>
        <?php echo form_label("Gruop Name"); ?> 
        <?php 
        $data=array(
        'name'=>'group_name',
        'placeholder'=>'enter group name'
        );
     ?>
         <?php echo form_input($data); ?>
    </div>
    <div>
        <?php $data=array(
        'name'=>'role[]',
        'value'=>'1',
        'type'=>'checkbox'
        );
        ?>
        <?php echo form_label('Admin'); ?>
        <?php echo form_checkbox($data); ?>
    </div>
    <div>
        <?php $data=array(
        'name'=>'role[]',
        'value'=>'2'
        );
        ?>
        <?php echo form_label('User'); ?>
        <?php echo form_checkbox($data); ?>
    </div>
    <div>
        <?php $data=array(
        'name'=>'role[]',
        'value'=>'3'
        );
        ?>
        <?php echo form_label('Editor'); ?>
        <?php echo form_checkbox($data); ?>
    </div>
    <div>
        <?php $data=array(
        'name'=>'role[]',
        'value'=>'4'
        );
        ?>
        <?php echo form_label('Others'); ?>
        <?php echo form_checkbox($data); ?>
    </div>
    <div>
        <?php $data=array(
        'type'=>'submit',
        'value'=>'Create'
        ); ?>
        <?php echo form_submit($data); ?>
    </div>
    <?php echo form_close(); ?>
</body>

3
  • Can you share tried code ? Commented Feb 4, 2016 at 11:44
  • i haven't tried the model code not sure where to start from Commented Feb 4, 2016 at 11:45
  • refer the link for how to use model in codeigniter ellislab.com/codeigniter/user-guide/general/models.html Commented Feb 4, 2016 at 11:52

2 Answers 2

2

First

Set "false" as default value at all those fields.

Second

If you can set only one role per user then you should use radiobox instead checkbox

Third

Capture the parameters sent by the post.

Assuming that you created a route for group/create_group that goes to the data_submitted method

public function data_submitted() {
    $data = array(
    'role' => $this->input->post('role'),
    //more info that you get from the post..
    );
    Now load your model and save it...

}

Sign up to request clarification or add additional context in comments.

1 Comment

thnx for that...i get it :)
0

Put off [] and in your php file logic your can do : $this->input->post("role"); and get value. If you want to do multi-choice's checkbox your must change to an unique name and set value to true for each of them.

Have nice day !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.