I have a form that the client can fill in with some info. It also has some checkboxses that the backend handles. When I submit the checkbox as unchecked I have noticed that its not even sent with the post so when the backend handles the form values, the checkbox's name doesn't exist and is undefined.
My question is why checkboxses are ignored when the form is posted if its unchecked? How could I fix it so It either sends true or false as the value when posting the form depending on if the checkbox is checked or not?
Here is an example bit from my form that I have on my clientside:
<form method="POST" action="example.com/api/">
<input type="checkbox" id="example_checkbox" name="example_checkbox" value="false" checked>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
I also have some jquery which sets the value of the checkbox in the html to false or true depending on if the client checks the checkbox or not:
$('#useRandomPassword').on("change", function() {
if ($('#useRandomPassword').is(":checked")) {
$('#useRandomPassword').val(true);
} else {
$('#useRandomPassword').val(false);
}
})