I've been looking for over an hour on the net, nothing showed up. I got some simple checkboxes, with a litle trick to style them, the classic hidden attribute and the label with the style. Nothing fancy. All I want is to send those checkboxes values/checked status through POST for proccesing. The problem is that whenever I change those values with jQuery, onClick, the inspector showes the changes, but in POST the input is not there anymore. I've tried setting the "checked" attribute with $.prop(). It worked for the inspector, but didn't worked on POST. Then I've changed to using values, setting all checkboxes as "checked" and changing the values with jQuery from 1 to 0 and back. The inspector showes the values changing, but the POST shows nothing.
Here the HTML form :
<form action="./ajax/process.php" enctype="multipart/form-data" method="post" id="admEmailParameteres1">
<input type="hidden" name="procesare" value="adm-process-parameters">
<input type="checkbox" id="sendConfEmailToClient" name="sendConfEmailToClient" value="<?= ($options['email_conf'] == 1 ? 1:0) ?>" class="hidden" checked>
<label for="sendConfEmailToClient" class="as-link tip label" onClick="toggleCheckSimple(this)" title="Trimite email de confirmare catre client la plasarea comenzii."><i class="fa fa-check label-check <?= ($options['email_conf'] == 1 ? 'active':'') ?>"></i> Client - email de confirmare la plasarea comenzii</label><br>
<input type="checkbox" id="sendAdvConfEmailToClient" name="sendAdvConfEmailToClient" value="<?= ($options['email_conf_sumar'] == 1 ? 1:0) ?>" class="hidden" checked>
<label for="sendAdvConfEmailToClient" class="as-link tip label" onClick="toggleCheckSimple(this)" title="Adauga si sumarul comenzii la email-ul de confirmare, trimis catre client la plasarea comenzii."><i class="fa fa-check label-check <?= ($options['email_conf_sumar'] == 1 ? 'active':'') ?>"></i> Client - adauga sumarul la email, la plasarea comenzii</label><br>
<input type="submit" class="btn btn-sm btn-success mb-5 " value="Salveaza modificarile" data-form="admEmailParameteres">
</form>
Here's the JS code:
function toggleCheckSimple(el){
$(el).find('.label-check').toggleClass('active');
var trg = $(el).attr('for');
if($('#'+trg).val() == 1){
$('input[name="'+trg+'"]').val(0);
}else{
$('input[name="'+trg+'"]').val(1);
}
}
And in the PHP side, if I call:
echo '<pre>';
print_r($_POST);
echo '</pre>';
The checkboxes are not there if they were changed with jQuery. If you don't touch them, they are there. Extremely strange adn upseting for me, as I am not a beginer. Can't figure this out.
foron the label will cause clicking the label to act like they clicked the checkbox itself, so there should already be a toggle going on with the checkbox.