Advertisement
Guest User

Untitled

a guest
May 1st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $('#buy-submit').click(function(event) {
  2.         // Stop the browser from submitting the form.
  3.         event.preventDefault();
  4.         var formData = $('#buyForm').serialize(),
  5.         userName = document.getElementById('name'),
  6.         userEmail = document.getElementById('email'),
  7.         sendButton = document.getElementById('buy-submit'),
  8.         r = document.getElementsByName('pago'),
  9.         pago = -1,
  10.         valor;
  11.         for(var i=0; i < r.length; i++){
  12.             if(r[i].checked) {
  13.                 pago = i;
  14.                 valor = r[i].value;
  15.             }
  16.         }
  17.         console.log(formData);
  18.         if (userName.value === '') {
  19.             swal("Oops", "Debe indicarnos su nombre...", "error");
  20.             console.log('Error en nombre');
  21.         } else if (userEmail.value === '') {
  22.             swal("Oops", "Debe indicarnos un correo de contacto...", "error");
  23.             console.log('Error en email');
  24.         } else if (pago == -1) {
  25.             swal("Oops", "Debe seleccionar un ciclo de facturación", "error");
  26.         } else {
  27.             $.ajax({
  28.                 type: 'POST',
  29.                 url: $('#contactForm').attr('action'),
  30.                 data: formData,
  31.                 success: function(res) {
  32.                     swal({
  33.                             title: "¡Perfecto!",
  34.                             text: "Su mensaje se ha enviado correctamente haga click en continuar",
  35.                             type: "success",
  36.                             showCancelButton: false,
  37.                             confirmButtonText: "continuar"
  38.                         }, function() {
  39.                         // Redirect the user
  40.                         window.location.href = 'http://lab.abr4xas.org/viser/';
  41.                     });
  42.                     sendButton.disabled = true;
  43.                     console.log('¡¡HELL YEAH!!');
  44.                     console.log(res);
  45.                 },
  46.                 error: function(err) {
  47.                     swal("Oops", "Algo salió mal... Intente enviar su mensaje más tarde.", "error");
  48.                     console.log('WHAT THE F... ');
  49.                     sendButton.disabled = false;
  50.                     console.log(err);
  51.                 }
  52.             });
  53.         }
  54.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement