submitHandler and .validate() issue

前端 未结 1 1630
旧巷少年郎
旧巷少年郎 2021-01-28 20:39

recently i had problem with attaching file into email, i handle that, thanks for you guys btw. Now i have next problem connected with \"fixed\" attching the file. Actually there

1条回答
  •  借酒劲吻你
    2021-01-28 20:52

    Issues 1 & 3 are because you misspelled required as requred in the uploaded_file rule and message.

    For issue 2 you need to return false from submitHandler to cancel the default form submission

    jQuery(function ($) {
        $("#formmail").validate({
    
            rules: {
                email: {
                    required: true,
                    email: true
                },
                name: {
                    required: true
    
                }, 
                message: {
                    required: true
                },
                uploaded_file: {
                    required: true
                }
            }, //koniec literału obiektowego rules
            messages: {
                email: {
                    required: "

    Podaj adres e-mail.

    ", email: "

    To nie jest prawidłowy
    adres e-mail.

    " }, name: { required: "

    Podaj swoje imię i nazwisko.

    " }, message: { required: "

    Wpisz treść listu motywacyjnego.

    " }, uploaded_file: { required: "

    Prześlij plik CV

    " } },submitHandler: function() { var thisForm = $('#formmail'); $('#formmail').fadeOut(function(){ //Display the "loading" message $("#loading-mail").fadeIn(function(){ //Post the form to the send script $.ajax({ type: 'POST', url: thisForm.attr("action"), data: thisForm.serialize(), //Wait for a successful response success: function(data){ //Hide the "loading" message $("#loading-mail").fadeOut(function(){ //Display the "success" message $("#success").text(data).fadeIn(); }); } }); }); }); return false } }); });

    Demo: Fiddle

    Note: The ajax submission will not work because of the file input in the form - for some alternates see this answer

    0 讨论(0)
提交回复
热议问题