0
How do I place whether or not the user has checked the form?
Form:
<form id="form2" method="post">
<input type="text" placeholder="NOME" value="" name="nome1" id="nome1" />
<input type="email" placeholder="EMAIL" value="" name="email1" id="email" />
<input type="tel" placeholder="TELEFONE" value="" name="telefone1" id="nome1" />
<div><input type="checkbox" name="two" value="desejo receber informações" /><label>Desejo receber informações e ofertas</label></div> //SERIA ESTE CHECKBOX
<button type="submit" class="btn m-btn">ENVIAR<span class="fa fa-angle-right"></span></button>
</form>
PHP:
<?php
// Check for empty fields
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
echo json_encode(array('error'=>'true'));
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$subject = ($_POST['subject'] ? $_POST['subject'] : "Website Contact Form: $name");
// Create the email and send the message
$to = '[email protected]';// Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = $subject;
$email_body = "You have received a new message from your website contact form.\n"."Here are the details:\nName: $name\nLast Name: $lastname\nEmail: $email_address\nPhone: $phone\nMessage:\n$message";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
echo json_encode(array('success'=>'true'));
return true;
?>
script:
$(function() {
$("input,textarea").jqBootstrapValidation({
preventSubmit: true,
submitError: function($form, event, errors) {
// additional error messages or events
},
submitSuccess: function($form, event) {
event.preventDefault(); // prevent default submit behaviour
// get values from FORM
var name = $("input#nome1").val();
var email = $("input#email1").val();
var phone = $("input#telefone1").val();
var firstName = name; // For Success/Failure Message
// Check for white space in name for Success/Fail message
if (firstName.indexOf(' ') >= 0) {
firstName = name.split(' ').slice(0, -1).join(' ');
}
$.ajax({
url: "././mail/contact_me-drive.php",
type: "POST",
dataType: 'json',
data: {
name: name,
email: email,
phone: phone,
message: message
},
cache: false,
success: function(data) {
if(data.error){
// Fail message
$('#success').html("<div class='alert alert-danger'>");
$('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×").append("</button>");
$('#success > .alert-danger').append("<span>Perdão " + firstName + ", parece que ocorreu uma falha no envio, tente novamente!</span>");
$('#success > .alert-danger').append('</div>');
//clear all fields
$('#form2').trigger("reset");
}
else if(data.success){
// Success message
$('#success').html("<div class='alert alert-success'>");
$('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×").append("</button>");
$('#success > .alert-success').append("<span>Sua mensagem foi enviada com sucesso </span>");
$('#success > .alert-success').append('</div>');
//clear all fields
$('#form2').trigger("reset");
}
}
})
},
filter: function() {
return $(this).is(":visible");
},
});
});
/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
$('#success').html('');
});
Ai has not left the html here follows : '<div><input type="checkbox" checked="checked" name="two" value="yes" id="two" /><label>I wish to receive information and offers</label></div>'
– Paulinha