{"id":1206,"date":"2017-03-05T23:27:03","date_gmt":"2017-03-05T17:57:03","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1206"},"modified":"2017-06-15T11:56:49","modified_gmt":"2017-06-15T06:26:49","slug":"simple-form-jquery-validation-php","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/simple-form-jquery-validation-php\/","title":{"rendered":"Simple form jquery validation in php"},"content":{"rendered":"<p><strong>Posted Date:04-03-2017<\/strong><\/p>\n<p>In this Post we will explain how to validate html\/php forms using jquery validator.<\/p>\n<p>First we will made a simple validation form using JQuery.<\/p>\n<h2 id=\"step1includejquery\">Step 1: Include jQuery\u00a0And\u00a0Validation Plugin<\/h2>\n<p>Create a new HTML file named index.html and include jQuery before the closing body tag:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;script src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.8.1\/jquery.min.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script src=&quot;http:\/\/ajax.aspnetcdn.com\/ajax\/jquery.validate\/1.9\/jquery.validate.min.js&quot;&gt;&lt;\/script&gt;\r\n<\/pre>\n<h2>Step 2:Create the HTML Form<\/h2>\n<p>we create basic html form<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n  &lt;form action=&quot;&quot; id=&quot;example&quot; method=&quot;post&quot;&gt;\r\n    &lt;label for=&quot;firstname&quot;&gt;First Name&lt;\/label&gt;\r\n    &lt;input type=&quot;text&quot; name=&quot;firstname&quot; id=&quot;firstname&quot; placeholder=&quot;Karthik&quot;\/&gt;\r\n    &lt;label for=&quot;lastname&quot;&gt;Last Name&lt;\/label&gt;\r\n    &lt;input type=&quot;text&quot; name=&quot;lastname&quot; id=&quot;lastname&quot; placeholder=&quot;N&quot;\/&gt;\r\n    &lt;label for=&quot;email&quot;&gt;Email&lt;\/label&gt;\r\n    &lt;input type=&quot;email&quot; name=&quot;email&quot; id=&quot;email&quot; placeholder=&quot;karthik@pheonixsolutions.com&quot;\/&gt;\r\n    &lt;label for=&quot;password&quot;&gt;Password&lt;\/label&gt;\r\n    &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot; placeholder=&quot;Password&quot;\/&gt;\r\n    &lt;button type=&quot;submit&quot;&gt;Register&lt;\/button&gt;\r\n &lt;\/form&gt;\r\n<\/pre>\n<h2>Step 3: Create the Validation Rules<\/h2>\n<p>Finally, initialize the form validation plugin give you form id and add every input field name into script validation<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n$(&quot;#example&quot;).validate({\r\n    \/\/ Specify validation rules\r\n    rules: {\r\n      firstname: &quot;required&quot;,\r\n      lastname: &quot;required&quot;,\r\n      email: {\r\n        required: true,\r\n        email: true\r\n      },\r\n      password: {\r\n        required: true,\r\n        minlength: 5\r\n      }\r\n    },\r\n      messages: {\r\n      firstname: &quot;Please enter your firstname&quot;,\r\n      lastname: &quot;Please enter your lastname&quot;,\r\n      password: {\r\n        required: &quot;Please provide a password&quot;,\r\n        minlength: &quot;Your password must be at least 5 characters long&quot;\r\n      },\r\n      email: &quot;Please enter a valid email address&quot;\r\n    },\r\n    \/\/ Make sure the form is submitted to the destination defined\r\n    \/\/ in the &quot;action&quot; attribute of the form when valid\r\n    submitHandler: function(form) {\r\n      form.submit();\r\n    }\r\n  });\r\n\r\n<\/pre>\n<h2>Conclusion:<\/h2>\n<p>if you are following above all the steps you getting this kind of code<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;script src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.8.1\/jquery.min.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script src=&quot;http:\/\/ajax.aspnetcdn.com\/ajax\/jquery.validate\/1.9\/jquery.validate.min.js&quot;&gt;&lt;\/script&gt;\r\n\r\n \t&lt;title&gt;Jquery Validation&lt;\/title&gt;\r\n \t&lt;script type=&quot;text\/javascript&quot;&gt;\r\n \t\t\/\/ Wait for the DOM to be ready\r\n$(function() {\r\n  \/\/ Initialize form validation on the registration form.\r\n  \/\/ It has the name attribute &quot;registration&quot;\r\n  $(&quot;#example&quot;).validate({\r\n    \/\/ Specify validation rules\r\n    rules: {\r\n      firstname: &quot;required&quot;,\r\n      lastname: &quot;required&quot;,\r\n      email: {\r\n        required: true,\r\n        email: true\r\n      },\r\n      password: {\r\n        required: true,\r\n        minlength: 5\r\n      }\r\n    },\r\n      messages: {\r\n      firstname: &quot;Please enter your firstname&quot;,\r\n      lastname: &quot;Please enter your lastname&quot;,\r\n      password: {\r\n        required: &quot;Please provide a password&quot;,\r\n        minlength: &quot;Your password must be at least 5 characters long&quot;\r\n      },\r\n      email: &quot;Please enter a valid email address&quot;\r\n    },\r\n    \/\/ Make sure the form is submitted to the destination defined\r\n    \/\/ in the &quot;action&quot; attribute of the form when valid\r\n    submitHandler: function(form) {\r\n      form.submit();\r\n    }\r\n  });\r\n});\r\n \t&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div class=&quot;container&quot;&gt;\r\n  &lt;h2&gt;Registration&lt;\/h2&gt;\r\n  &lt;form action=&quot;&quot; id=&quot;example&quot; method=&quot;post&quot;&gt;\r\n\r\n    &lt;label for=&quot;firstname&quot;&gt;First Name&lt;\/label&gt;\r\n    &lt;input type=&quot;text&quot; name=&quot;firstname&quot; id=&quot;firstname&quot; placeholder=&quot;Karthik&quot;\/&gt;\r\n\r\n    &lt;label for=&quot;lastname&quot;&gt;Last Name&lt;\/label&gt;\r\n    &lt;input type=&quot;text&quot; name=&quot;lastname&quot; id=&quot;lastname&quot; placeholder=&quot;N&quot;\/&gt;\r\n\r\n    &lt;label for=&quot;email&quot;&gt;Email&lt;\/label&gt;\r\n    &lt;input type=&quot;email&quot; name=&quot;email&quot; id=&quot;email&quot; placeholder=&quot;karthik@pheonixsolutions.com&quot;\/&gt;\r\n\r\n    &lt;label for=&quot;password&quot;&gt;Password&lt;\/label&gt;\r\n    &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot; placeholder=&quot;Password&quot;\/&gt;\r\n\r\n    &lt;button type=&quot;submit&quot;&gt;Register&lt;\/button&gt;\r\n\r\n  &lt;\/form&gt;\r\n&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Posted Date:04-03-2017 In this Post we will explain how to validate html\/php forms using jquery validator. First we will made [&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":[],"class_list":["post-1206","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-js","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1206","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=1206"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1206\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}