Sounds simple enough, but I just cannot make it work. I am trying to insert a checkbox value to database. If it checked, insert Y, if not, insert N. In my DOM, I see that the value of checkbox is changing to N after I click it, but the values are not changed in database. Maybe it is something small and stupid that I am missing.
So the default value is N.
Here's the HTML:
<div class="funkyradio">
<div class="funkyradio-success">
<input type="checkbox" name="animalCare" id="animalCare" value="N"/>
<label for="animalCare">Hoolitsen loomade eest:</label>
</div>
</div>
JS
//I have a lot more of those checkboxes
$('#cleaningOk, #animalCare, #homeSchooling, #worktime_lenght, #sickChildren, #isSmoking, #isTattoo, #animalsOk, #disabledChildren, #singleParent, #driversLicense, #babyOk').change(function(){
if ($(this).is(':checked')) {
$(this).val('Y');
} else {
$(this).val('N');
}
});
For inserting I use formValidation.io plugin and if the checkbox is changed, I don't even see the N in formdata under the network tab, else I see the Y.
.on('success.form.fv', function(e, data) {
// Prevent form submission
e.preventDefault();
console.log("validated");
var $form = $(e.target),
formData = new FormData(),
params = $form.serializeArray(),
files = $form.find('[name="userProfilePhoto"]')[0].files;
$.ajax({
url: $form.attr('action'),
data: formData,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data) {},
error: function(jqXHR, textStatus, errorThrown, data) {
console.log(jqXHR, textStatus, errorThrown, data);
}
});
});
PHP
////SERVICES
if (isset($_POST["cleaningOk"], $_POST['animalCare'], $_POST['homeSchooling'])){
$cleaningOk = $_POST['cleaningOk'];
$animalCare = $_POST['animalCare'];
$homeSchooling = $_POST['homeSchooling'];
$nanny_services = $user_home->runQuery("INSERT into services (user_id, koristab, loomade_hoolitsus, koduõpetamine) VALUES (:user_id, :cleaningOk, :animalCare, :homeSchooling) ON DUPLICATE KEY UPDATE koristab= VALUES(koristab), loomade_hoolitsus= VALUES(loomade_hoolitsus), koduõpetamine=VALUES(koduõpetamine)");
$nanny_services->bindparam(':cleaningOk', $cleaningOk, PDO::PARAM_STR);
$nanny_services->bindparam(':animalCare', $animalCare, PDO::PARAM_STR);
$nanny_services->bindparam(':homeSchooling', $homeSchooling, PDO::PARAM_STR);
$nanny_services->bindparam(':user_id', $user_id, PDO::PARAM_STR);
$nanny_services->execute();
$response_array["status"] = 'success';
}
////SERVICES
koristab= VALUES(koristab), loomade_hoolitsus= VALUES(loomade_hoolitsus)should throw something. Also why update to the same value?var_dump($_POST)?FormDataeither.