Reputation: 5277
I have a set of checkboxes and have disabled few which I want to be always true and user can not unselect them. When I submit the form I am not getting the disabled checkboxes value. How to get this values
<? echo "<PRE>"; print_r($_POST);?>
<form method="post">
<input type="checkbox" name="t[1]" value="1" disabled="disabled" checked="checked" />1
<input type="checkbox" name="t[2]" value="2" disabled="disabled" checked="checked" />2
<input type="checkbox" name="t[3]" value="3" disabled="disabled" checked="checked" />3
<input type="checkbox" name="t[4]" value="4" />4
<input type="checkbox" name="t[5]" value="5" />5
<input type="checkbox" name="t[6]" value="6" />6
<input type="checkbox" name="t[7]" value="7" />7
<input type="submit" />
</form>
I Should get values 1,2,3 always and the values user selected if any
Upvotes: 1
Views: 9522
Reputation: 471
For each disabled checkboxes use <input type="hidden" ... /> with the same name and value.
Upvotes: 7
Reputation: 1379
As a fact, disabled elements are disabled and will not be sent, as @BluesRockAddict already said.
What you can do is using JavaScript for disallowing unchecking the checkbox. You might use something like this <checkbox [...] onclick="return false" onkeydown="return false"
But still, as you disable JavaScript, this will not work.
Upvotes: 2
Reputation: 15683
For disabled checkboxes, the values will never be posted to the server. One possible workaround would be to add some javascript code that would enable disabled checkboxes upon submitting the form.
Upvotes: 1