Can we post Unchecked Radio Button value?

user2782577 picture user2782577 · Mar 21, 2014 · Viewed 7.2k times · Source

I have a situation where i do need unchecked radio button value. Is it possible to send unchecked radio button value through form in php? If yes, then can you please explain?

Answer

andy mccullough picture andy mccullough · Mar 21, 2014
<input type="hidden" name="myField" value="false" />
<input type="checkbox" name="myField" value="true" />

both fields have the same name, if the checkbox isn't checked, the hidden field will be submitted, if the checkbox is checked, it will virtually override the the hidden field.

On a side note, are your sure radio buttons wouldn't be better suited to your needs, you will be able to see the definite answer for each questions, whereas checkboxes are more for submitted only the selected checkboxes. Failing that you could always assume that all checkboxes that were not submitted as checked, could be assumed to be unchecked.