Jules
Jules

Reputation: 143

Posting status of multiple checkboxes

I have 3 checkboxes that are part of form and all I want to do is post this when the form is submitted. Every other form item posts no problem but I can't get the checkbox status at all? What am I doing wrong, it seems to me they have to set in javascript but why when everything else on the form posts no problem?

code is :

<div align="left"> <label><input type="checkbox" value="NO" name="signs" /> Non sign written</label></div>
<div align="left"> <label><input type="checkbox" value="NO" name="disabled" /> Disabled access</label></div>
<div align="left"> <label><input type="checkbox" value="NO" name="female" /> Female driver</label></div>

and the code in the php file to get the data is :

$signs = $_REQUEST['signs'];
$disabled = $_REQUEST['disabled'];
$female = $_REQUEST['female'];

Thanks

Upvotes: 0

Views: 33

Answers (1)

ajai Jothi
ajai Jothi

Reputation: 2294

This is a default behavior of HTML Form. Unchecked checkbox values are not considered by browser while submitting form. You have to handle it with default value at your PHP end.

$DEFAULT_VALUE = 'YES';

$signs = $_REQUEST['signs']?$_REQUEST['signs']:$DEFAULT_VALUE;
$disabled = $_REQUEST['disabled']?$_REQUEST['disabled']:$DEFAULT_VALUE;
$female = $_REQUEST['female']?$_REQUEST['female']:$DEFAULT_VALUE;

Hope this helps

Upvotes: 2

Related Questions