Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save miukimiu/5065998 to your computer and use it in GitHub Desktop.
Save miukimiu/5065998 to your computer and use it in GitHub Desktop.
Uma validação de um formulário em ajax/jquery para wordpress
jQuery(function($) {
$.data(document.body, 'ajaxUrl', '<?php echo admin_url('admin-ajax.php'); ?>');
});
$(function() {
$('.error').hide();
$("#reservas .button").click(function() {
var name = $("#name").val();
if (name == "") {
$("label#name_error").show();
$("input#name").focus();
return false;
}
var email = $("#email").val();
if (email == "") {
$("#email_error").show();
$("input#email").focus();
return false;
}
var phone = $("#phone").val();
if (phone == "") {
$("label#phone_error").show();
$("input#phone").focus();
return false;
}
var comentarios = $("#comentarios").val();
var date = $("#date").val();
var horario = $("#horario").val();
var adultos = $("#adultos").val();
var criancas = $("#criancas").val();
var rest_name = $("#rest_name").val();
var dataString = 'name='+ name + '&email=' + email + '&date=' + date + '&horario=' + horario + '&adultos=' + adultos + '&criancas=' + criancas + '&rest_name=' + rest_name + '&phone=' + phone + '&comentarios=' + comentarios;
$.ajax({
type: "POST",
url: $.data(document.body, 'ajaxUrl' ),
data: dataString,
success: function() {
$('#contact_form').html("<div id='message'></div>");
$('#message').html("<h2>A sua reserva foi enviada!</h2>")
.append("<p>Confirme o email com os dados da reserva.</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='checkmark' src='images/check.png' />");
});
}
});
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment