I’m encountering an odd issue. I need to asynchronously post data to a 3rd party system. Everything works fine except the two checkboxes at the end of my form. Unfortunately, I don’t have access to the system’s db, so success/failure is simply determined if any results show up in the admin area of that system.
The form and jQuery are constructed in PHP. Relevant fields below:
Have a Representative Call Me: <input id="00N60000002Rtib" name="00N60000002Rtib" type="checkbox" value="1" /><br>
Send Marketing Material and Updated News: <input id="00N60000002Rtig" name="00N60000002Rtig" type="checkbox" value="1" /><br>
The data construction (PHP):
foreach ($values as $key => $val) {
if ($key == '00N60000002Rtib' || $key == '00N60000002Rtig') {
$data .= "$key : $val, ";
} else {
$data .= "$key : \"$val\", ";
}
}
$data = substr($data, 0, -2); // remove trailing comma and space
And jQuery construction:
<script type="text/javascript">
$(window).load(function() {
$.post('http://somesite.com', { <?php echo $data; ?> });
});
</script>
Viewing HTML source confirms that my post $data is constructed properly.
What’s really strange is that a pure HTML form with the same fields posts properly. I’m stumped. Any ideas?
I ran into this same issue and figured out that even if the checkboxes were empty and didn’t seem to be included in the post request, they were still being marked as “checked” by my server (and thus being inserted into database). Make sure the values are not empty to avoid any weirdness from ajax submissions with checkboxes.
This will unset post keys for empty values: