Guest User

Untitled

a guest
May 27th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. $("form").submit(function(event) {
  2. event.preventDefault();
  3. var phone_input = $(this).find("input[type=tel]");
  4. var phone_number = phone_input.val().replace(/[^0-9]/g,"");
  5.  
  6. if (phone_number.length === 0 ) {
  7. phone_input.notify("Введите номер телефона", {position:"bottom" , className: 'error'})
  8. }
  9.  
  10. if (phone_number.length < 12 && phone_number.length >= 4) {
  11. phone_input.notify("Номер введён не полностью", {position:"bottom" , className: 'warn', gap: 0, autoHideDelay: 3000});
  12. }
  13. if (phone_number.length === 12) {
  14. var data = $(this).serializeArray();
  15. data.push ({name: 'client', value: client_info});
  16. data.push ({name: 'href', value: href});
  17. data.push ({name: 'search', value: search});
  18. data.push ({name: 'ref', value: ref});
  19. var thisForm = $(this);
  20. var thisBtn = thisForm.find("button");
  21. $.ajax({
  22. url: 'php/mail.php',
  23. type: 'POST',
  24. data: data,
  25. success: function(data){
  26. console.log(data);
  27. thisBtn.notify("Заявка принята", {position:"bottom center", className: 'success'});
  28. thisForm.find("input").val("");
  29. thisForm.trigger("reset");
  30.  
  31. },
  32. error: function(data) {
  33. if (data === 'error') {
  34. thisBtn.notify("Ошибка на сервере", {position:"bottom center", className: 'error'} );
  35. thisForm.find("input").val("");
  36. thisForm.trigger("reset");
  37. }
  38. }
  39. });
  40. return false;
  41. }
  42. });
Add Comment
Please, Sign In to add comment