Hi all,
I've bee doing some research on checkboxes in PHP and how they work. I've also been playing with them in a project of mine and have found some interesting results.
I found this thread - thread181-27567 and jpadie stated that an unchecked checkbox returns nothing.
I have found that in my project, it does not appear to be the case. Let me describe my settings and what I did to acheive a result.
Firstly my checkboxes are linked to fields that are set to TinyInt meaning they can only accept a 1 or a 0.
Now what I wanted to do was to have the checkboxes checked if there was a 1 in these fields to indicate that the checkbox had in fact been checked previously.
The code below is what I placed into the HTML tag to acheive this
What I found was that if I checked a box previously so that the field value was 1 and then unchecked the box the next time around, the field value would then be 0.
I can only conclude that regradless of what the checkbox is set at (checked or unchecked) that it sends something back to the database.
Now my method works fine in this instance, is this method flawed at all?
I'm using an MVC structure in my project, is there any other way of checking the checkboxes when the fields are set at 1?
-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
I've bee doing some research on checkboxes in PHP and how they work. I've also been playing with them in a project of mine and have found some interesting results.
I found this thread - thread181-27567 and jpadie stated that an unchecked checkbox returns nothing.
I have found that in my project, it does not appear to be the case. Let me describe my settings and what I did to acheive a result.
Firstly my checkboxes are linked to fields that are set to TinyInt meaning they can only accept a 1 or a 0.
Now what I wanted to do was to have the checkboxes checked if there was a 1 in these fields to indicate that the checkbox had in fact been checked previously.
The code below is what I placed into the HTML tag to acheive this
Code:
<?php if ($post['DLApp']==1){ echo "checked='checked'";}?>
What I found was that if I checked a box previously so that the field value was 1 and then unchecked the box the next time around, the field value would then be 0.
I can only conclude that regradless of what the checkbox is set at (checked or unchecked) that it sends something back to the database.
Now my method works fine in this instance, is this method flawed at all?
I'm using an MVC structure in my project, is there any other way of checking the checkboxes when the fields are set at 1?
-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."