I'm creating an HTML form that need to be first reviewed by javascript and then if a checkbox is selected it process PHP code.
<form class="form" method="POST" action="index.php" onsubmit="return
gdpr(e)">
<input class="form-check-input" type="checkbox" value="" name="gdpr"
id="gdpr_privacy">
<input class="btn btn-primary btn-block" type="submit" name="submit"
placeholder="Send" id="submit"></input>
</form>
Javascript:
function gdpr(e){
e.preventDefault();
e.stopPropagation();
let privacy = document.getElementById('gdpr_privacy').checked;
if(privacy == false){
window.alert("false");
return false;
}
else{
window.alert("true");
return true;
}
}
Right now the pages refresh too if the checkbox is selected or not selected, it should execute index.php only when return is true.