Hello friends i have a trouble.
I'm trying to use this code to get dynamically, variables and values of a form, but there is a countless number checkbox, which may or not marked, I would like to know how can I get an off or "0" in case not this a checkbox labeled, these data have been used .ajax and data:
Short Example of checkboxes:
<input name="p-sis-0110-1" type="checkbox">
<input name="p-sis-0110-2" type="checkbox">
<input name="p-sis-0110-3" type="checkbox">
<input name="p-sis-0110-4" type="checkbox">
<input name="p-sis-0110-5" type="checkbox">
<input name="p-sis-0110-6" type="checkbox">
or
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
Ajax:
.$("#formarea").serialize()
PHP:
foreach ($_POST as $key => $value){
echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>"
}
I appreciate any help to solve this little dilemma.
Only "successful" controls are submitted. An unchecked checkbox or radio button is not "successful".
You need to declare a default value with a hidden input. Make sure the hidden input comes before the checkbox so if the checkbox is checked it will override the default hidden input since the names are the same:
To use an array you need to explicitly define the indexes so they are the same: