0
I have a problem with ajax, which is not taking the data entered in the email form, despite sending the emails.
Follow the form code:
$(function(){
$('#nome, #email, #assunto, #message').on('keypress', function(e){
if (e.keyCode == 13) {
e.preventDefault();
$('#envia').click();
}
});
$("#envia").click(function(){
var name = $("#nome").val(),
emai = $("#email").val(),
ass = $("#assunto").val(),
mess = $("#message").val();
var campo = {
nome: $("#nome").val(),
email: $("#email").val(),
assunto: $("#assunto").val(),
message: $("#message").val()
};
if(!campo.nome || !campo.assunto || !campo.email || !campo.message){
$.alert({
title: 'Atenção',
content: 'Todos os campos sao obrigatorios!',
animation: 'bottom',
icon: 'fa fa-warning',
animationSpeed: 700,
keyboardEnabled: true,
columnClass: 'col-md-4 col-md-offset-4'
});
return;
}
$.ajax("email.php",{
type: "POST",
data:{'nome': name, 'email': emai, 'assunto': ass, 'mensagem': mess} }).done(function(){
$.alert({
title: 'Sucesso',
content: 'E-mail enviado com sucesso!',
animation: 'bottom',
icon: 'fa fa-warning',
animationSpeed: 700,
keyboardEnabled: true,
columnClass: 'col-md-4 col-md-offset-4'
});
return;
}).fail(function(){
$.alert({
title: 'Opss..',
content: 'Ocorreu um erro durante o processo tente novamente!',
animation: 'bottom',
icon: 'fa fa-warning',
animationSpeed: 700,
keyboardEnabled: true,
columnClass: 'col-md-4 col-md-offset-4'
});
return;
});
});
});
<div class="form-group col-md-6">
<input type="text" name="name" id="nome" class="form-control" required placeholder="Nome">
</div>
<div class="form-group col-md-6">
<input type="email" name="email" id="email" required class="form-control" placeholder="E-mail">
</div>
<div class="form-group col-md-12">
<input type="text" name="subject" id="assunto" required class="form-control" placeholder="Assunto">
</div>
<div class="form-group col-md-12">
<textarea name="message" id="message" id="message" required class="form-control" rows="8" placeholder="Sua Mensagem. "></textarea>
</div>
<div class="form-group col-md-12">
<button name="submit" id="envia" class="btn btn-primary pull-right">Enviar</button>
</div>
could give a little more context, which data are not being taken, post your form HTML. I think this will get a response :)
– Brunno
not being taken all the data I’m asking you to take
– Leonardo Costa
added the html part
– Leonardo Costa
Use the.log console and see how far your code is picking up data
– Henrique Felix
gave a console.log(data) and it gave me this data is not defined error
– Leonardo Costa
try to remove single quotes from their variables inside the
data
– user28595
changed nothing continues in the same error
– Leonardo Costa
Changed the date to
data: {
 'a' : name,
 'b' : emai,
 'c' : ass,
 'd' :mess
 }
?– user28595
I see by the breakpoint ta strange he’s getting the values of the variables and ta picking
– Leonardo Costa
the problem may be in your email.php file too.
– user28595
but it was right until I decided to do with ajax
– Leonardo Costa
Even changing your date the way I posted keeps giving error? If yes, inform which.
– user28595
yes keeps giving the same error.
– Leonardo Costa
I made a test to see if it is php and not and I did not play the form there and filled the fields he send me the email straight
– Leonardo Costa
Where are you giving error then? If you are sending the email, it means that the data is being sent by ajax normally.
– user28595
not I did the test by php only php to see if my php code was wrong and it is not wrong. the error is in ajax he is sending the email but not picking up the variables is not sending the fields filled the email he is sending intendeu?
– Leonardo Costa
ai ta dar esse erro de data is not defined
– Leonardo Costa
could help me I remade ajax and I managed to get the email now it is sending email only with the field filled and the other empty fields I will edit my code ajax must be some small mistake I’m missing if anyone can help
– Leonardo Costa