Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. $(document).ready(function() {
  2. var formulario = document.forms["formContato"];
  3. $(formulario).bootstrapValidator({
  4. // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
  5. feedbackIcons: {
  6. valid: 'glyphicon glyphicon-ok',
  7. invalid: 'glyphicon glyphicon-remove',
  8. validating: 'glyphicon glyphicon-refresh'
  9. },
  10. fields: {
  11. first_name: {
  12. validators: {
  13. stringLength: {
  14. min: 2,
  15. },
  16. notEmpty: {
  17. message: 'Por favor digite seu nome'
  18. }
  19. }
  20. },
  21. email: {
  22. validators: {
  23. notEmpty: {
  24. message: 'Por favor digite seu e-mail'
  25. },
  26. emailAddress: {
  27. message: 'Por favor digite um endereço de e-mail válido'
  28. }
  29. }
  30. },
  31. phone: {
  32. validators: {
  33. notEmpty: {
  34. message: 'Por favor digite seu número de telefone'
  35. },
  36. phone: {
  37. country: 'BR',
  38. message: 'Por favor digite um número de telefone válido'
  39. }
  40. }
  41. },
  42. comment: {
  43. validators: {
  44. stringLength: {
  45. min: 10,
  46. max: 2000,
  47. message:'A mensagem deve ter de 10 a 2000 caracteres'
  48. },
  49. notEmpty: {
  50. message: 'Por favor digite uma mensagem'
  51. }
  52. }
  53. }
  54. }
  55. })
  56. .on('success.form.bv', function(e) {
  57. $('#success_message').slideDown({ opacity: "show" }, "slow") // Do something ...
  58. $('formulario').data('bootstrapValidator').resetForm();
  59.  
  60. // Prevent form submission
  61. e.preventDefault();
  62.  
  63. // Get the form instance
  64. var $form = $(e.target);
  65.  
  66. // Get the BootstrapValidator instance
  67. var bv = $form.data('bootstrapValidator');
  68.  
  69. // Use Ajax to submit form data
  70. console.log(JSON.stringify(form.data));
  71. $.post($form.attr('action'), $form.serialize(), function(result) {
  72. console.log(result);
  73. }, 'json');
  74. });
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement