• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
not posting values of 0 (zero) for checkbox

#1
[eluser]Brad K Morse[/eluser]
Code:
<?=form_checkbox('enabled['.$r->id.']', 1, $r->enabled)?>

renders:
Code:
<input type="checkbox" name="enabled[25]" value="1" checked="checked"  />
<input type="checkbox" name="enabled[7]" value="1"  />

The table field "enabled" stores 1 or 0 and checks the appropriate checkboxes, as seen here: http://cl.ly/4ogc (screenshot)

It will run queries when the checkbox value is 1, whether it was already checked (as that record's enabled field is 1) and whatever checkboxes the user selects.

The problem is, it does not update any fields that are unchecked, whether unchecked by default or unchecked by the user.

I enabled the profiler and I can tell it completely ignores posting anything if the value is set to 0 (zero).

I know if the the checkbox is not checked, it is blank, so the post does not see a value for that input, therefore it doesn't need to return anything.

It worked fine using a dropdown method

Code:
<select name="enabled[&lt;?=$r->id?&gt;]">
  <option value="1" &lt;?php if($r->enabled == 1) { print 'selected=""selected"'; } ?&gt;>Yes</option>
  <option value="0" &lt;?php if($r->enabled == 0) { print 'selected=""selected"'; } ?&gt;>No</option>
</select>

or
Code:
&lt;?=form_dropdown('enabled['.$r->id.']', $enabled_options, $r->enabled)?&gt;

Is this possible using a checkbox?

#2
[eluser]JonoB[/eluser]
Yep, same problem here. If the checkbox is not selected, then absolutely nothing is posted for that element.

#3
[eluser]JonoB[/eluser]
Bizarely, seems like this is 'normal' html behaviour.
http://ellislab.com/forums/viewthread/168765/
http://ellislab.com/forums/viewthread/181646/

#4
[eluser]Brad K Morse[/eluser]
This looks to be the fix: http://stackoverflow.com/questions/51026...22#5102722


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.