Advertisement
Guest User

Untitled

a guest
Apr 29th, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.29 KB | None | 0 0
  1. $(document).ready(function()
  2. {
  3.   $("#botao").click(function()
  4.   {
  5.     $("#forma").validate({
  6.       rules:{
  7.         nome:{
  8.           required: true,
  9.           minlength: 3
  10.         },
  11.         email:{
  12.           required: true,
  13.           email: true
  14.         },
  15.         cpf:{
  16.           required: true,
  17.           minlength: 14
  18.         },
  19.         data_nasc:{
  20.           required: true,
  21.           minlength: 10
  22.         },
  23.         sexo:{
  24.           required: true
  25.         }
  26.       },
  27.       messages:{
  28.         nome:{
  29.           required: "O campo nome é obrigatório.",
  30.           minlength: "Mínimo de 3 caracteres."
  31.         },
  32.         email:{
  33.           required: "O campo email é obrigatório.",
  34.           email: "Email inválido. Insira corretamente."
  35.         },
  36.         cpf:{
  37.           required: "O campo CPF/CNPJ é obrigatório.",
  38.           minlength: "Número inválido. Insira corretamente."
  39.         },
  40.         data_nasc:{
  41.           required: "O campo data de nascimento é obrigatório.",
  42.           minlength: "Data inválida. Insira corretamente."
  43.         },
  44.         sexo:{
  45.           required: "É necessário escolher uma opção."
  46.         }
  47.       }
  48.     });
  49.     if($('#forma').validate().form() == true){
  50.       $('#loading').css({'display': 'inline'});
  51.       $.ajax({
  52.         url: './php/main.php',
  53.         type: 'POST',
  54.         async: true,
  55.        
  56.         data: {
  57.           nome: $('#nome').val(),
  58.           cpf: $('#cpf').val(),
  59.           email: $('#email').val(),
  60.           data_nasc: $('#data_nasc').val(),
  61.           sexo: $("[name='sexo']:checked").val()
  62.         },
  63.        
  64.         success: function(text) {
  65.           $('#testeajax').text('');
  66.           //$(text).appendTo('#testeajax');
  67.           $('#loading').css({'display': 'none'});
  68.           $('#testeajax').html(text);
  69.  
  70.           /*if(text == 's')
  71.           {
  72.             alert('Cliente cadastrado com sucesso!\nUsuário:'+$('#nome').val()+'\nSenha: enc123');
  73.           }
  74.           else
  75.           {
  76.             alert('Problema ao cadastrar o cliente');
  77.           }*/
  78.         },
  79.         error: function() {
  80.           $('#testeajax').text('Erro no Ajax!');
  81.         }
  82.         /*complete: function()
  83.         {
  84.           $('#loading').css({'display': 'none'});
  85.         }*/
  86.       });
  87.     }
  88.   });
  89. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement