Validation on click in contact form 7












1















I am building custom step-by-step form based on Contact Form 7 and i need to validate field before going to next section. how i can call validate function on click? I can't find it in documentation.



$( "#next-section" ).click(function() {

//call validate function (how to do this)??

if('validate function no errors') {
//call my scripts
}
});









share|improve this question























  • i think you need this . stackoverflow.com/questions/27798264/…

    – Noman
    Mar 30 '16 at 10:55
















1















I am building custom step-by-step form based on Contact Form 7 and i need to validate field before going to next section. how i can call validate function on click? I can't find it in documentation.



$( "#next-section" ).click(function() {

//call validate function (how to do this)??

if('validate function no errors') {
//call my scripts
}
});









share|improve this question























  • i think you need this . stackoverflow.com/questions/27798264/…

    – Noman
    Mar 30 '16 at 10:55














1












1








1


1






I am building custom step-by-step form based on Contact Form 7 and i need to validate field before going to next section. how i can call validate function on click? I can't find it in documentation.



$( "#next-section" ).click(function() {

//call validate function (how to do this)??

if('validate function no errors') {
//call my scripts
}
});









share|improve this question














I am building custom step-by-step form based on Contact Form 7 and i need to validate field before going to next section. how i can call validate function on click? I can't find it in documentation.



$( "#next-section" ).click(function() {

//call validate function (how to do this)??

if('validate function no errors') {
//call my scripts
}
});






jquery wordpress contact-form-7






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 30 '16 at 9:32









PonciuszPonciusz

67112




67112













  • i think you need this . stackoverflow.com/questions/27798264/…

    – Noman
    Mar 30 '16 at 10:55



















  • i think you need this . stackoverflow.com/questions/27798264/…

    – Noman
    Mar 30 '16 at 10:55

















i think you need this . stackoverflow.com/questions/27798264/…

– Noman
Mar 30 '16 at 10:55





i think you need this . stackoverflow.com/questions/27798264/…

– Noman
Mar 30 '16 at 10:55












3 Answers
3






active

oldest

votes


















0














You can do this :



$( "#next-section" ).click(function() {
$('your-form').submit();
});





share|improve this answer
























  • not working. its good idea but how i can init submit on contactform7 in jquery?

    – Ponciusz
    Mar 30 '16 at 10:05











  • The problem will occur also when i want to validate and fields after visible content has errors so it will not let use go further more

    – Ponciusz
    Mar 30 '16 at 10:19











  • No need init submit. submit() is a function jquery for submit a form. But not verify the fields. Because the .submit() don't use html 5 property in dom.

    – Greg
    Mar 30 '16 at 11:30



















0














You can call .validate plugin for form validation.



$( "#next-section" ).click(function() {
$("#form").validate({
rules: {
name: "required",
},
messages: {
name: "name is required",
},
submitHandler: function(form) {
form.submit();
}
});
});





share|improve this answer

































    0














    I have faced the same problem and got a solution.



    I have 2 steps form, and I had an idea to submit the form and then check whether input fields on 1st step were validated (obviously, the form cannot be sent cause there are few fields on a 2nd step, this was made just to use CF7 validation).



    $('.go_to_step_2').on('click', function () {

    var input = $('input[name="your-name"]'),
    form = $(this).parents('.wpcf7-form');

    form.submit();

    // trigger just one time! so validation works correctly in the 2nd step
    form.parent().one('wpcf7:invalid', function() {

    if( !input.hasClass('wpcf7-not-valid') ) {

    // this will hide valid-tips from step 2
    $('.step_2').find('.wpcf7-not-valid-tip').fadeOut(0);

    // do stuff to show step 2
    }
    });
    });





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36304816%2fvalidation-on-click-in-contact-form-7%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You can do this :



      $( "#next-section" ).click(function() {
      $('your-form').submit();
      });





      share|improve this answer
























      • not working. its good idea but how i can init submit on contactform7 in jquery?

        – Ponciusz
        Mar 30 '16 at 10:05











      • The problem will occur also when i want to validate and fields after visible content has errors so it will not let use go further more

        – Ponciusz
        Mar 30 '16 at 10:19











      • No need init submit. submit() is a function jquery for submit a form. But not verify the fields. Because the .submit() don't use html 5 property in dom.

        – Greg
        Mar 30 '16 at 11:30
















      0














      You can do this :



      $( "#next-section" ).click(function() {
      $('your-form').submit();
      });





      share|improve this answer
























      • not working. its good idea but how i can init submit on contactform7 in jquery?

        – Ponciusz
        Mar 30 '16 at 10:05











      • The problem will occur also when i want to validate and fields after visible content has errors so it will not let use go further more

        – Ponciusz
        Mar 30 '16 at 10:19











      • No need init submit. submit() is a function jquery for submit a form. But not verify the fields. Because the .submit() don't use html 5 property in dom.

        – Greg
        Mar 30 '16 at 11:30














      0












      0








      0







      You can do this :



      $( "#next-section" ).click(function() {
      $('your-form').submit();
      });





      share|improve this answer













      You can do this :



      $( "#next-section" ).click(function() {
      $('your-form').submit();
      });






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 30 '16 at 9:42









      GregGreg

      750320




      750320













      • not working. its good idea but how i can init submit on contactform7 in jquery?

        – Ponciusz
        Mar 30 '16 at 10:05











      • The problem will occur also when i want to validate and fields after visible content has errors so it will not let use go further more

        – Ponciusz
        Mar 30 '16 at 10:19











      • No need init submit. submit() is a function jquery for submit a form. But not verify the fields. Because the .submit() don't use html 5 property in dom.

        – Greg
        Mar 30 '16 at 11:30



















      • not working. its good idea but how i can init submit on contactform7 in jquery?

        – Ponciusz
        Mar 30 '16 at 10:05











      • The problem will occur also when i want to validate and fields after visible content has errors so it will not let use go further more

        – Ponciusz
        Mar 30 '16 at 10:19











      • No need init submit. submit() is a function jquery for submit a form. But not verify the fields. Because the .submit() don't use html 5 property in dom.

        – Greg
        Mar 30 '16 at 11:30

















      not working. its good idea but how i can init submit on contactform7 in jquery?

      – Ponciusz
      Mar 30 '16 at 10:05





      not working. its good idea but how i can init submit on contactform7 in jquery?

      – Ponciusz
      Mar 30 '16 at 10:05













      The problem will occur also when i want to validate and fields after visible content has errors so it will not let use go further more

      – Ponciusz
      Mar 30 '16 at 10:19





      The problem will occur also when i want to validate and fields after visible content has errors so it will not let use go further more

      – Ponciusz
      Mar 30 '16 at 10:19













      No need init submit. submit() is a function jquery for submit a form. But not verify the fields. Because the .submit() don't use html 5 property in dom.

      – Greg
      Mar 30 '16 at 11:30





      No need init submit. submit() is a function jquery for submit a form. But not verify the fields. Because the .submit() don't use html 5 property in dom.

      – Greg
      Mar 30 '16 at 11:30













      0














      You can call .validate plugin for form validation.



      $( "#next-section" ).click(function() {
      $("#form").validate({
      rules: {
      name: "required",
      },
      messages: {
      name: "name is required",
      },
      submitHandler: function(form) {
      form.submit();
      }
      });
      });





      share|improve this answer






























        0














        You can call .validate plugin for form validation.



        $( "#next-section" ).click(function() {
        $("#form").validate({
        rules: {
        name: "required",
        },
        messages: {
        name: "name is required",
        },
        submitHandler: function(form) {
        form.submit();
        }
        });
        });





        share|improve this answer




























          0












          0








          0







          You can call .validate plugin for form validation.



          $( "#next-section" ).click(function() {
          $("#form").validate({
          rules: {
          name: "required",
          },
          messages: {
          name: "name is required",
          },
          submitHandler: function(form) {
          form.submit();
          }
          });
          });





          share|improve this answer















          You can call .validate plugin for form validation.



          $( "#next-section" ).click(function() {
          $("#form").validate({
          rules: {
          name: "required",
          },
          messages: {
          name: "name is required",
          },
          submitHandler: function(form) {
          form.submit();
          }
          });
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 30 '16 at 10:17

























          answered Mar 30 '16 at 10:11









          RaviKant SharmaRaviKant Sharma

          163




          163























              0














              I have faced the same problem and got a solution.



              I have 2 steps form, and I had an idea to submit the form and then check whether input fields on 1st step were validated (obviously, the form cannot be sent cause there are few fields on a 2nd step, this was made just to use CF7 validation).



              $('.go_to_step_2').on('click', function () {

              var input = $('input[name="your-name"]'),
              form = $(this).parents('.wpcf7-form');

              form.submit();

              // trigger just one time! so validation works correctly in the 2nd step
              form.parent().one('wpcf7:invalid', function() {

              if( !input.hasClass('wpcf7-not-valid') ) {

              // this will hide valid-tips from step 2
              $('.step_2').find('.wpcf7-not-valid-tip').fadeOut(0);

              // do stuff to show step 2
              }
              });
              });





              share|improve this answer




























                0














                I have faced the same problem and got a solution.



                I have 2 steps form, and I had an idea to submit the form and then check whether input fields on 1st step were validated (obviously, the form cannot be sent cause there are few fields on a 2nd step, this was made just to use CF7 validation).



                $('.go_to_step_2').on('click', function () {

                var input = $('input[name="your-name"]'),
                form = $(this).parents('.wpcf7-form');

                form.submit();

                // trigger just one time! so validation works correctly in the 2nd step
                form.parent().one('wpcf7:invalid', function() {

                if( !input.hasClass('wpcf7-not-valid') ) {

                // this will hide valid-tips from step 2
                $('.step_2').find('.wpcf7-not-valid-tip').fadeOut(0);

                // do stuff to show step 2
                }
                });
                });





                share|improve this answer


























                  0












                  0








                  0







                  I have faced the same problem and got a solution.



                  I have 2 steps form, and I had an idea to submit the form and then check whether input fields on 1st step were validated (obviously, the form cannot be sent cause there are few fields on a 2nd step, this was made just to use CF7 validation).



                  $('.go_to_step_2').on('click', function () {

                  var input = $('input[name="your-name"]'),
                  form = $(this).parents('.wpcf7-form');

                  form.submit();

                  // trigger just one time! so validation works correctly in the 2nd step
                  form.parent().one('wpcf7:invalid', function() {

                  if( !input.hasClass('wpcf7-not-valid') ) {

                  // this will hide valid-tips from step 2
                  $('.step_2').find('.wpcf7-not-valid-tip').fadeOut(0);

                  // do stuff to show step 2
                  }
                  });
                  });





                  share|improve this answer













                  I have faced the same problem and got a solution.



                  I have 2 steps form, and I had an idea to submit the form and then check whether input fields on 1st step were validated (obviously, the form cannot be sent cause there are few fields on a 2nd step, this was made just to use CF7 validation).



                  $('.go_to_step_2').on('click', function () {

                  var input = $('input[name="your-name"]'),
                  form = $(this).parents('.wpcf7-form');

                  form.submit();

                  // trigger just one time! so validation works correctly in the 2nd step
                  form.parent().one('wpcf7:invalid', function() {

                  if( !input.hasClass('wpcf7-not-valid') ) {

                  // this will hide valid-tips from step 2
                  $('.step_2').find('.wpcf7-not-valid-tip').fadeOut(0);

                  // do stuff to show step 2
                  }
                  });
                  });






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 '18 at 18:08









                  Rostyk ChaikivskyiRostyk Chaikivskyi

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36304816%2fvalidation-on-click-in-contact-form-7%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                      How to change which sound is reproduced for terminal bell?

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?