contact.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. $(document).ready(function(){
  2. (function($) {
  3. "use strict";
  4. jQuery.validator.addMethod('answercheck', function (value, element) {
  5. return this.optional(element) || /^\bcat\b$/.test(value)
  6. }, "type the correct answer -_-");
  7. // validate contactForm form
  8. $(function() {
  9. $('#contactForm').validate({
  10. rules: {
  11. name: {
  12. required: true,
  13. minlength: 2
  14. },
  15. subject: {
  16. required: true,
  17. minlength: 4
  18. },
  19. number: {
  20. required: true,
  21. minlength: 5
  22. },
  23. email: {
  24. required: true,
  25. email: true
  26. },
  27. message: {
  28. required: true,
  29. minlength: 20
  30. }
  31. },
  32. messages: {
  33. name: {
  34. required: "come on, you have a name, don't you?",
  35. minlength: "your name must consist of at least 2 characters"
  36. },
  37. subject: {
  38. required: "come on, you have a subject, don't you?",
  39. minlength: "your subject must consist of at least 4 characters"
  40. },
  41. number: {
  42. required: "come on, you have a number, don't you?",
  43. minlength: "your Number must consist of at least 5 characters"
  44. },
  45. email: {
  46. required: "no email, no message"
  47. },
  48. message: {
  49. required: "um...yea, you have to write something to send this form.",
  50. minlength: "thats all? really?"
  51. }
  52. },
  53. submitHandler: function(form) {
  54. $(form).ajaxSubmit({
  55. type:"POST",
  56. data: $(form).serialize(),
  57. url:"contact_process.php",
  58. success: function() {
  59. $('#contactForm :input').attr('disabled', 'disabled');
  60. $('#contactForm').fadeTo( "slow", 1, function() {
  61. $(this).find(':input').attr('disabled', 'disabled');
  62. $(this).find('label').css('cursor','default');
  63. $('#success').fadeIn()
  64. $('.modal').modal('hide');
  65. $('#success').modal('show');
  66. })
  67. },
  68. error: function() {
  69. $('#contactForm').fadeTo( "slow", 1, function() {
  70. $('#error').fadeIn()
  71. $('.modal').modal('hide');
  72. $('#error').modal('show');
  73. })
  74. }
  75. })
  76. }
  77. })
  78. })
  79. })(jQuery)
  80. })