Advertisement
Guest User

LuMendoza

a guest
Oct 16th, 2013
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. /*
  2. Jquery Validation using jqBootstrapValidation
  3. example is taken from jqBootstrapValidation docs
  4. */
  5. $(function() {
  6.  
  7. $("input,textarea").jqBootstrapValidation(
  8. {
  9. preventSubmit: true,
  10. submitError: function($form, event, errors) {
  11. // something to have when submit produces an error ?
  12. // Not decided if I need it yet
  13. },
  14. submitSuccess: function($form, event) {
  15. event.preventDefault(); // prevent default submit haviour
  16. // get values from FORM
  17. var name = $("input#name").val();
  18. var email = $("input#email").val();
  19. var message = $("textarea#message").val();
  20. var firstName = name; // For Success/Failure Message
  21. // Check for white space in name for Success/Fail message
  22. if (firstName.indexOf(' ') >= 0) {
  23. firstName = name.split(' ').slice(0, -1).join(' ');
  24. }
  25. $.ajax({
  26. url: "./bin/contact_me.php",
  27. type: "POST",
  28. data: {name: name, email: email, message: message},
  29. cache: false,
  30. success: function() {
  31. // Success message
  32. $('#success').html("<div class='alert alert-success'>");
  33. $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
  34. .append( "</button>");
  35. $('#success > .alert-success')
  36. .append("<strong>Your message has been sent. </strong>");
  37. $('#success > .alert-success')
  38. .append('</div>');
  39.  
  40. //clear all fields
  41. $('#contactForm').trigger("reset");
  42. },
  43. error: function() {
  44. // Fail message
  45. $('#success').html("<div class='alert alert-danger'>");
  46. $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
  47. .append( "</button>");
  48. $('#success > .alert-danger').append("<strong>Sorry "+firstName+" it seems that my mail server is not responding...</strong> Could you please email me directly to <a href='mailto:me@example.com?Subject=Message_Me from myprogrammingblog.com;>me@example.com</a> ? Sorry for the inconvenience!");
  49. $('#success > .alert-danger').append('</div>');
  50. //clear all fields
  51. $('#contactForm').trigger("reset");
  52. },
  53. })
  54. },
  55. filter: function() {
  56. return $(this).is(":visible");
  57. },
  58. });
  59.  
  60. $("a[data-toggle=\"tab\"]").click(function(e) {
  61. e.preventDefault();
  62. $(this).tab("show");
  63. });
  64. });
  65.  
  66.  
  67. /*When clicking on Full hide fail/success boxes */
  68. $('#name').focus(function() {
  69. $('#success').html('');
  70. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement