Salve a tutti,
ho questo codice su 2 pagine:
La questione semplicemente è: il checkbox non funziona nella pagina dove viene compilato il form.
Grazie
ho questo codice su 2 pagine:
PHP:
(quello evidenziato in rosso)
<script>
$(document).ready(function (e){
$("#frmContact").on('submit',(function(e){
e.preventDefault();
$("#mail-status").hide();
$('#send-message').hide();
$('#loader-icon').show();
$.ajax({
url: "contact.php",
type: "POST",
dataType:'json',
data: {
"name":$('input[name="name"]').val(),
"surname":$('input[name="surname"]').val(),
"address":$('input[name="address"]').val(),
"city":$('input[name="city"]').val(),
"phone":$('input[name="phone"]').val(),
"phone2":$('input[name="phone2"]').val(),
"name2":$('input[name="name2"]').val(),
"surname2":$('input[name="surname2"]').val(),
"email":$('input[name="email"]').val(),
"content":$('textarea[name="content"]').val(),
"consenso":$('checkbox[name="consenso"]').val(),
"g-recaptcha-response":$('textarea[id="g-recaptcha-response"]').val()},
success: function(response){
$("#mail-status").show();
$('#loader-icon').hide();
if(response.type == "error") {
$('#send-message').show();
$("#mail-status").attr("class","error");
} else if(response.type == "message"){
$('#send-message').hide();
$("#mail-status").attr("class","success");
}
$("#mail-status").html(response.text);
},
error: function(){}
});
}));
});
</script>
.......
<input type="checkbox" id="consenso" name="consenso" value="consenso" <?php echo $consenso; ?> class="required consenso" aria-required="true" required>
.......
(seconda pagina)
(quello evidenziato in rosso)
$user_name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$user_surname = filter_var($_POST["surname"], FILTER_SANITIZE_STRING);
$user_address = filter_var($_POST["address"], FILTER_SANITIZE_STRING);
$user_city = filter_var($_POST["city"], FILTER_SANITIZE_STRING);
$user_phone = filter_var($_POST["phone"], FILTER_SANITIZE_STRING);
$user_phone2 = filter_var($_POST["phone2"], FILTER_SANITIZE_STRING);
$user_name2 = filter_var($_POST["name2"], FILTER_SANITIZE_STRING);
$user_surname2 = filter_var($_POST["surname2"], FILTER_SANITIZE_STRING);
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$content = filter_var($_POST["content"], FILTER_SANITIZE_STRING);
$consenso = filter_var($_POST["consenso"], FILTER_SANITIZE_STRING);
.....
if(empty($user_name)) {
$empty[] = "<b>Name</b>";
}
if(empty($user_surname)) {
$empty[] = "<b>Cognome</b>";
}
if(empty($user_address)) {
$empty[] = "<b>Indirizzo</b>";
}
if(empty($user_city)) {
$empty[] = "<b>Comune di residenza</b>";
}
if(empty($user_phone)) {
$empty[] = "<b>Telefono</b>";
}
if(empty($user_phone2)) {
$empty[] = "<b>Cellulare</b>";
}
if(empty($user_name2)) {
$empty[] = "<b>Nome partecipante</b>";
}
if(empty($user_surname2)) {
$empty[] = "<b>Cognome partecipante</b>";
}
if(empty($user_email)) {
$empty[] = "<b>Email</b>";
}
if(empty($content)) {
$empty[] = "<b>Richiesta</b>";
}
if (isset($_POST['consenso'])) {
$consenso='checked="yes"';
} else {
$consenso='';
}
Grazie
Ultima modifica di un moderatore: