I have the following form
which displays a checkbox
:
<form>
<input type="checkbox" class="custom-control-input" id="ch" value="y" required>
<button id="CT" type="button" >Go</button>
</form>
And my AJAX
script:
<script>
//ST
$('#CT').click(function(){
var fullname = document.getElementById("fn").value;
var username = document.getElementById("un").value;
var emailAdd = document.getElementById("em").value;
var password = document.getElementById("pd").value;
var check = document.getElementById("ch").value;
$.ajax({
type:'POST',url:'ajax/signup.php',
data:'fn='+fullname+'&un='+username+'&em='+emailAdd+'&pd='+password+'&ch='+check,
beforeSend:function(){ $('#WAIT').show(); },
success:function(data){ $('#HERE').html(data); }
});
});
//SD
</script>
Lastly, here is my ajax/signup.php
script:
<?php
$FN = $_POST["fn"];
$UN = $_POST["un"];
$EM = $_POST["em"];
$PD = $_POST["pd"];
$CH = $_POST["ch"];
if(empty($FN) OR empty($UN) OR empty($EM) OR empty($PD) OR $CH != "y"){
echo""?>
<script>
$("form").addClass("was-validated");
</script>
<?"";
}
?>
How to check if the checkbox
was validated on the client side?