Jump to content

codeigniter form_checkbox


anujgarg

Recommended Posts

Hi All,

 

Below question is related to codeigniter:

I am using a form having some dynamic checkboxes that are created by applying a loop over the result fetched from database. I am looking the way of handling these checkboxes that are set to checked or unchecked. More specifically, if I check a checkbox then its DB entry should be changed to ‘1’ and if I uncheck it then entry should be ‘0’.

 

I have used the following and noticed when I write:

<? foreach ($page[‘questions’] as $question) { ?>

 

<?=form_checkbox(“Q_{$question[‘questionid’]}_active”,1,$question[‘active’]) ?>

and

<?=form_checkbox(“Q_{$question[‘questionid’]}_active”,1,$question[‘active’]) ?>

 

<? } ?>

 

then the values in DB are being set ‘1’ and ‘0’ respectively.

 

I also noticed that after setting ‘0’ in the above statement, I am able to update DB table to ‘1’ (by checking the checkboxes) but after setting ‘1’ in that statement, DB table is not being updated to ‘0’ again.

 

Further code goes to:

                    switch ($page['type']) {

                                    case 'questions':

foreach ($page['questions'] as $child) {

$save = array();

 

foreach (array('title', 'title_user', 'optional', 'reprompt', 'active', 'choices') as $field)

{

if ( isset($data[$key = "Q_{$child['questionid']}_$field"]) && ($data[$key] != $child[$field]) )

$save[$field] = $data[$key];

}

if ($save) {

$this->Profile->dbs[$profile]->where('questionid', $child['questionid']);

$this->Profile->dbs[$profile]->update('questions', $save);

}

}

break;

 

Is there any problem in my update query?

Please suggest..

 

Thanks

Anuj

Link to comment
https://forums.phpfreaks.com/topic/178944-codeigniter-form_checkbox/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.