I'm trying to pass a form for $ .ajax but when I get to the part of success: function (data) block .... I'm not an expert at this and just start practicing programming if someone is kind enough to explain how poderme send a 'Notify", here is my code:
<script>
$(function () {
$("#contacto_web").submit(function(e) {
e.preventDefault();
$.ajax({
url : "contacto_web.php",
type : "POST",
data : {
$("#contacto_web").serialize();
},
before : function () {
},
success : function (data) {
if(data == "si_enviado"){
$UIkit.notify({
message : 'Bazinga!',
status : 'info',
timeout : 5000,
pos : 'top-center'
});
}else if(data == "no_enviado"){
$UIkit.notify({
message : 'Bazinga!',
status : 'danger',
timeout : 5000,
pos : 'top-center'
});
}
},
error : function () {
},
});
});
});
</script>
Uikit Framework Link:
php code:
<?php
if(filter_input_array(INPUT_POST)){
$nombres = filter_input(INPUT_POST, "nombres");
$apellidos = filter_input(INPUT_POST, "apellidos");
$tlfno1 = filter_input(INPUT_POST, "tlfno1");
$tlfno2 = filter_input(INPUT_POST, "tlfno2");
$email1 = filter_input(INPUT_POST, "email1");
$email2 = filter_input(INPUT_POST, "email2");
$nombre_razonsocial = filter_input(INPUT_POST, "nombre_razonsocial");
$pais = filter_input(INPUT_POST, "pais");
$direccion = filter_input(INPUT_POST, "direccion");
$sms_form = filter_input(INPUT_POST, "sms_form");
$to = "diego.cardenas@udatabox.com";
$title = "Correo de contacto desde la pagina web";
$headers = "From: $email1" . "\r\n";
$message ="
Contacto desde la pagina web\n
$nombres $apellidos\n
Telefono $tlfno1 | Movil $tlfno2\n
Correo principal $email1, Correo alternativo $email2\n\n
Nombre / Razon social $nombre_razonsocial\n
Pais de procedencia $pais\n
Direccion $direccion\n
Mensaje\n
$sms_form
";
if(mail($to,$title,$message,$headers)){
echo "si_enviado";
}else{
echo "no_enviado";
}
}
Aucun commentaire:
Enregistrer un commentaire