{"id":3355,"date":"2019-01-09T18:48:57","date_gmt":"2019-01-09T13:18:57","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=3355"},"modified":"2019-01-30T17:33:52","modified_gmt":"2019-01-30T12:03:52","slug":"form-validation-with-php","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/form-validation-with-php\/","title":{"rendered":"Form Validation with PHP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Date Posted<\/strong>: 09\/01\/2019<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post we will and validate a simple form using HTML and PHP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 1<\/strong>: Create the html form using following code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n\t&lt;title&gt;&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n &lt;form  method=\"POST\" enctype=\"multipart\/form-data\" id=\"alumini-form\"&gt;\t\n\n Name &lt;input type=\"text\" name=\"name\" value=\"\"&gt;\nAddress &lt;input type=\"text\" name=\"address\" value=\"\"&gt;\nEmail &lt;input type=\"text\" name=\"email\" value=\"\"&gt;\n&lt;input type=\"radio\" name=\"howMany\" value=\"zero\"&gt; 0\n&lt;input type=\"radio\" name=\"howMany\" value=\"one\"&gt; 1\n&lt;input type=\"radio\" name=\"howMany\" value=\"two\"&gt; 2\n&lt;input type=\"radio\" name=\"howMany\" value=\"twoplus\"&gt; More than 2\n&lt;select name=\"favFruit[]\" size=\"4\" multiple&gt;\n &lt;option value=\"apple\"&gt;Apple&lt;\/option&gt;\n &lt;option value=\"banana\"&gt;Banana&lt;\/option&gt;\n &lt;option value=\"plum\"&gt;Plum&lt;\/option&gt;\n &lt;option value=\"pomegranate\"&gt;Pomegranate&lt;\/option&gt;\n &lt;option value=\"strawberry\"&gt;Strawberry&lt;\/option&gt;\n &lt;option value=\"watermelon\"&gt;Watermelon&lt;\/option&gt;\n&lt;\/select&gt;\n&lt;input type=\"checkbox\" name=\"brochure\" value=\"Yes\"&gt;\n&lt;input type=\"submit\" name=\"submit\" value=\"Submit\"&gt;\n\n&lt;\/form&gt;\n\n\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2:<\/strong> Please use the following code to validate the php forms. You can add the below code before html code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if ($_SERVER[\"REQUEST_METHOD\"] == \"POST\") {\n    if (empty($_POST[\"name\"])) {\n        $nameErr = \"Missing\";\n    }\n    else {\n        $name = $_POST[\"name\"];\n    }\n\n    if (empty($_POST[\"address\"])) {\n        $addrErr = \"Missing\";\n    }\n    else {\n        $address = $_POST[\"address\"];\n    }\n\n    if (empty($_POST[\"email\"]))  {\n        $emailErr = \"Missing\";\n    }\n    else {\n        $email = $_POST[\"email\"];\n    }\n\n    if (!isset($_POST[\"howMany\"])) {\n        $howManyErr = \"You must select 1 option\";\n    }\n    else {\n        $howMany = $_POST[\"howMany\"];\n    }\n\n    if (empty($_POST[\"favFruit\"])) {\n        $favFruitErr = \"You must select 1 or more\";\n    }\n    else {\n        $favFruit = $_POST[\"favFruit\"];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Thank you! for using <a href=\"https:\/\/pheonixsolutions.com\/\">PHEONIX SOLUTIONS.<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You find this tutorial helpful? Share with your friends to keep it alive. Be the first to comment, we value your suggestions. For further queries please comment below. <br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Date Posted: 09\/01\/2019 In this post we will and validate a simple form using HTML and PHP. Step 1: Create [&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":[527,495,273],"class_list":["post-3355","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-form","tag-html","tag-php","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-S7","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3355","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=3355"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3355\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}