{"id":1610,"date":"2017-06-07T02:49:54","date_gmt":"2017-06-06T21:19:54","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1610"},"modified":"2026-09-08T11:33:06","modified_gmt":"2026-09-08T06:03:06","slug":"jquery-validation-two-forms-different-tabs","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/jquery-validation-two-forms-different-tabs\/","title":{"rendered":"JQuery Validation on Two Forms in different Tabs"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Form validation is an important part of web application development. When a form is divided into multiple steps or tabs, each section needs to be validated before the user moves to the next step.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we will explain how to implement jQuery validation for multiple forms displayed in different tabs or steps. Each form is validated before moving to the next step, while the final form handles the complete submission.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before implementing jQuery validation on multiple forms, make sure you have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Basic knowledge of HTML.<\/li>\n\n\n\n<li>Basic knowledge of JavaScript and jQuery.<\/li>\n\n\n\n<li>jQuery included in the application.<\/li>\n\n\n\n<li>jQuery Validation Plugin included in the application.<\/li>\n\n\n\n<li>Basic understanding of HTML forms.<\/li>\n\n\n\n<li>Basic understanding of form validation and submission.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create the Forms<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add the necessary jQuery and jQuery Validation Plugin files in the HTML head section.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create three separate forms representing different steps:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;form id=\"form1\">Step #1\n\n&lt;input type=\"text\" name=\"field1\" \/>&lt;br \/>\n\n&lt;button type=\"button\" id=\"gotoStep2\">Go to step 2&lt;\/button>\n\n&lt;\/form>\n\n&lt;form id=\"form2\">Step #2\n\n&lt;input type=\"text\" name=\"field2\" \/>&lt;br \/>\n\n&lt;button type=\"button\" id=\"gotoStep3\">Go to step 3&lt;\/button>\n\n&lt;\/form>\n\n&lt;form id=\"form3\">Step #3\n\n&lt;input type=\"text\" name=\"field3\" \/>&lt;br \/>\n\n&lt;button type=\"submit\">Complete&lt;\/button>\n\n&lt;\/form><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The three forms represent three different steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 1<\/strong> contains <code>field1<\/code> and a button to move to Step 2.<\/li>\n\n\n\n<li><strong>Step 2<\/strong> contains <code>field2<\/code> and a button to move to Step 3.<\/li>\n\n\n\n<li><strong>Step 3<\/strong> contains <code>field3<\/code> and the final submit button.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Add jQuery Validation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following script code inside the script tag:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(document).ready(function () {\n\n$('#form1').validate({\n\n\/\/ rules\n\n    rules: {\n\n        field1: {\n\n            required: true\n\n}\n\n}\n\n});\n\n\n$('#form2').validate({\n\n```javascript\n    rules: {\n\n        field2: {\n\n            required: true\n\n}\n\n}\n\n});\n\n\n$('#form3').validate({\n\n```javascript\n    rules: {\n\n        field3: {\n\n            required: true\n\n}\n\n},\n\n    submitHandler: function (form) {\n\n\/\/ serialize and join data for all forms\n\n\/\/ ajax submit\n\nalert('go ajax');\n\nreturn false;\n\n}\n\n});\n\n\n$('#gotoStep2').on('click', function () {\n\n```javascript\nif ($('#form1').valid()) {\n\n\/\/ code to reveal step 2\n\n        $('#form1').hide();\n\n        $('#form2').show();\n\n}\n\n});\n\n\n$('#gotoStep3').on('click', function () {\n\n```javascript\nif ($('#form2').valid()) {\n\n\/\/ code to reveal step 3\n\n        $('#form2').hide();\n\n        $('#form3').show();\n\n}\n\n});\n\n\/\/ there is no third click handler since the plugin takes care of this with the\n\n\/\/ built-in submitHandler callback function on the last form.\n\n});<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The validation rules are applied separately to each form. The <code>required<\/code> rule ensures that the user provides a value for each required field before proceeding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Validate the First Form<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The first form is validated when the user clicks the <strong>Go to step 2<\/strong> button:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$('#gotoStep2').on('click', function () {\n    if ($('#form1').valid()) { \n        $('#form1').hide();\n        $('#form2').show(); \n } \n});<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>.valid()<\/code> method checks whether the fields in <code>form1<\/code> satisfy the configured validation rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the form is valid, the first form is hidden and the second form is displayed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Validate the Second Form<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The second form follows the same process:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$('#gotoStep3').on('click', function () {\n\n    if ($('#form2').valid()) {\n\n        $('#form2').hide();\n\n        $('#form3').show();\n\n    }\n\n});<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the second form passes validation, it is hidden and the third form is displayed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Handle the Final Form Submission<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The third form uses the <code>submitHandler<\/code> provided by the jQuery Validation Plugin:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">submitHandler: function (form) {\n\n    \/\/ serialize and join data for all forms\n\n    \/\/ ajax submit\n\n    alert('go ajax');\n\n    return false;\n\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>submitHandler<\/code> is executed only after the final form passes validation. The form data can be serialized and submitted using AJAX as required by the application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">jQuery Validation provides a simple way to validate multiple forms displayed across different tabs or steps. Each form can have its own validation rules, allowing users to complete one step before moving to the next.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this implementation, the first and second forms are validated before the user can proceed to the next step, while the final form uses the <code>submitHandler<\/code> callback to handle the final submission.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">1. Can jQuery validate multiple forms separately?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. The jQuery Validation Plugin can be initialized separately for each form using its respective form ID. Each form can have its own validation rules.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. How can I prevent the user from moving to the next tab if validation fails?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <code>.valid()<\/code> method on the current form before displaying the next form. If validation fails, the next step will not be displayed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if ($('#form1').valid()) {\n    $('#form1').hide();\n    $('#form2').show();\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. How is the final form submitted?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The final form uses the <code>submitHandler<\/code> callback provided by the jQuery Validation Plugin. This callback can be used to process the form data or submit it through AJAX.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/jquery-custom-validation\/?utm_source=chatgpt.com\">jQuery Custom Validation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/check-uncheck-checkbox-using-jquery\/?utm_source=chatgpt.com\">Check\/Uncheck Checkbox Using jQuery<\/a><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Form validation is an important part of web application development. When a form is divided into multiple steps or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[273],"class_list":["post-1610","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-php","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-pY","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1610"}],"version-history":[{"count":3,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1610\/revisions"}],"predecessor-version":[{"id":11524,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1610\/revisions\/11524"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}