PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The following is part of a code snippet someone from this forum once gave me which generates the key/value pairs from a form submission. The problem I now have is that checkbox pairs are only included if the value is positive. So if I unselect a checkbox which has previously been selected, it will not be included in the key/value pairs and thus will not update the database. I don't understand how to include the checkbox value when it is negative. I have also included an example of the code I use for checkboxes. Any help greatly appreciated.
Pcoder, yes, I can also get the value if I make an explicit list of values in the mysql query like so:
abc = '$abc',
The above would apply a negative boolean to the value in the database...but the whole point is to have the key/value pairs built dynamically instead of hard-coded.
I'm surprised that the checkboxes with empty values are not being included in $_POST. If a form field type is "text" and the value is emply, it is still included in $_POST.
I have discovered a workaround which works for me. By assigning hidden fields with the same names as the checkboxes giving them the value "" and placing them all at the beginning of the set of form fields, I am able to toggle the checkboxes on and off.
This is an acceptable solution for me because I have to explicitly name form fields anyway. It's only the processing of the form data that I want to be reusable.