Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we post Unchecked Radio Button value?

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?

like image 427
user2782577 Avatar asked Mar 21 '14 11:03

user2782577


1 Answers

<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.

like image 193
andy mccullough Avatar answered Oct 09 '22 03:10

andy mccullough