{"id":376,"date":"2024-04-11T01:48:25","date_gmt":"2024-04-11T01:48:25","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=376"},"modified":"2024-04-19T03:30:10","modified_gmt":"2024-04-19T03:30:10","slug":"form-validation","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/04\/11\/form-validation\/","title":{"rendered":"\ud3fc \uc720\ud6a8\uc131\ud655\uc778\ud558\uae30Form validation(1)"},"content":{"rendered":"\n<p>\uc720\ud6a8\uc131 \uac80\uc0ac\ub780 \ub370\uc774\ud130 \uc804\uc1a1\uc744 \ud558\uae30 \uc704\ud574 \ud3fc\uc758 \uc785\ub825 \ud544\ub4dc\uc5d0 \uac12\uc744 \uc785\ub825\ud560 \ub54c \uac12\uc774 \uc815\uc0c1\uc801\uc73c\ub85c \uc785\ub825\ub418\uc5c8\ub294\uc9c0 \ud655\uc778 \ud558\uae30 \uc704\ud55c \ubd80\ubd84 \uc785\ub2c8\ub2e4.<br>\uc774\ub7ec\ud55c \ud3fc\uc758 \uc720\ud6a8\uc131\uac80\uc0ac\ub294 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\ub97c \uc774\uc6a9\ud569\ub2c8\ub2e4.<br>\uc624\ub80c\uc9c0\uc0c9 \uceec\ub7ec\uc758 \ucf54\ub4dc\ub294 \uc0c8\ub86d\uac8c \ucd94\uac00\ub41c \ucf54\ub4dc \uc785\ub2c8\ub2e4.<br>Validation is the part to ensure that the value is entered normally when you enter the value in the input field of the form to transfer data.<br>Validation of these forms uses JavaScript.<br>The orange code is a newly added code.<br><br><strong>1.\uc774\ub984 \uc785\ub825\ud544\ub4dc \ud655\uc778\ud558\uae30 Check the Name Input Field<\/strong><br>&#8211; \uc774\ub984\uc774 \uc815\uc0c1\uc801\uc73c\ub85c \uc785\ub825\ub418\uc5c8\ub294\uc9c0 \uccb4\ud06c\ud569\ub2c8\ub2e4. <br> Check that the name is entered successfully.<br>&#8211; id=&#8221;name&#8221; : \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\uc5d0\uc11c \uc774 id \uac12\uc744 \uc774\uc6a9\ud574\uc11c \ud655\uc778\ud569\ub2c8\ub2e4.<br>                    JavaScript checks using this ID value.<br>&#8211; placeholder = &#8220;[\ud14d\uc2a4\ud2b8 text]&#8221; : \uc785\ub825\ud544\ub4dc\uc5d0 \uc544\ubb34 \uac12\uc774 \uc785\ub825\ub418\uc9c0 \uc54a\uc740 \uacbd\uc6b0 \ubcf4\uc5ec\uc9c8 \ud14d\uc2a4\ud2b8 \uc785\ub2c8\ub2e4.<br>                                               Text to be displayed if no value is entered in the input field.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;input type=\"name\" class=\"form-control\" id=\"name\" placeholder=\"\ub2f9\uc2e0\uc758 \uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Enter Your Name)\" name=\"name\"&gt;<\/code><\/pre>\n\n\n\n<p><strong>2.\ud328\uc2a4\uc6cc\ub4dc \uc785\ub825\ud544\ub4dc \ud655\uc778\ud558\uae30 Check the Password Input Field<\/strong><br>&#8211; \ud328\uc2a4\uc6cc\ub4dc\uac00 \uc815\uc0c1\uc801\uc73c\ub85c \uc785\ub825\ub418\uc5c8\ub294\uc9c0 \uccb4\ud06c\ud569\ub2c8\ub2e4.<br>Check that the Passworrd is entered successfully.<br>&#8211; id=&#8221;pwd&#8221; name=&#8221;paswd&#8221;\uc778 \uac83\uc744 \uc8fc\uc758\ud558\uc138\uc694<br>Watch out for id=&#8221;pwd&#8221; name=&#8221;paswd&#8221;<br>&#8211; id\ub294 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\uc5d0\uc11c \ud655\uc778\ud558\uae30 \uc704\ud55c \ubd80\ubd84\uc774\uace0 name\uc740 php\uc5d0\uc11c \ud655\uc778\ud558\uae30 \uc704\ud55c \ubd80\ubd84\uc785\ub2c8\ub2e4.<br>id is the part to check in JavaScript and name is the part to check in php.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;input type=\"password\" class=\"form-control\" id=\"pwd\" placeholder=\"Enter password\" name=\"pswd\"&gt;<\/code><\/pre>\n\n\n\n<p><strong>3.\ubc84\ud2bc \ud0c0\uc785 \uc218\uc815Modify button type<\/strong><br>&#8211; \ubc84\ud2bc \ud0c0\uc785\uc744 submit\uc5d0\uc11c button\uc73c\ub85c \uc218\uc815\ud569\ub2c8\ub2e4.<br>Modify the button type from submit to button.<br>&#8211; \ubc84\ud2bc\uc744 \ud074\ub9ad\ud588\uc744 \ub54c \uc2e4\ud589\ub420 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \ud568\uc218 \uc774\ubca4\ud2b8\ub97c \ucd94\uac00\ud569\ub2c8\ub2e4.<br>Adds a JavaScript function event that will run when the button is clicked.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;button type=\"button\" onClick=\"frmSubmit();\" class=\"btn btn-primary\"&gt;Submit&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<p><br><strong>4. \uc720\ud6a8\uc131 \uac80\uc0ac \uba54\uc138\uc9c0\ub97c \ubcf4\uc5ec\uc904 div\ud0dc\uadf8 \ucd94\uac00\ud558\uae30<\/strong><br>Add div tag to show validation message<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>... &lt;div id=\"errorName\"&gt;&lt;\/div&gt; ...\n... &lt;div id=\"errorPwd\"&gt;&lt;\/div&gt; ...<\/code><\/pre>\n\n\n\n<p><br><strong>\uc804\uccb4\ucf54\ub4dc(full code)<\/strong><br>-\uc544\ub798\uc758 \ub9c1\ud06c\ub97c \ud1b5\ud574\uc11c \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4<br>You can test it through the link below.<br>test : <a rel=\"noreferrer noopener\" href=\"https:\/\/freelifemakers.org\/lec\/form3.php\" target=\"_blank\">https:\/\/freelifemakers.org\/lec\/form3.php<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n    &lt;head&gt;\n      &lt;title&gt;Bootstrap 5 Example&lt;\/title&gt;\n      &lt;meta charset=\"utf-8\"&gt;\n      &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt;\n      &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.3\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\n      &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.3\/dist\/js\/bootstrap.bundle.min.js\"&gt;&lt;\/script&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;form <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-orange-color\">name=\"frm\"<\/mark> action=\".\/form_action2.php\" method=\"get\"&gt;\n        &lt;div class=\"mb-3 mt-3\"&gt;\n            &lt;label for=\"name\" class=\"form-label\"&gt;\uc774\ub984(Name):&lt;\/label&gt;\n            &lt;input type=\"name\" class=\"form-control\" <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-orange-color\">id=\"name\" placeholder=\"\ub2f9\uc2e0\uc758 \uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Enter Your Name)\"<\/mark> name=\"name\"&gt;\n            <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-orange-color\">&lt;div id=\"errorName\"&gt;&lt;\/div&gt;<\/mark>\n        &lt;\/div&gt;\n        &lt;div class=\"mb-3\"&gt;\n            &lt;label for=\"pwd\" class=\"form-label\"&gt;Password:&lt;\/label&gt;\n            &lt;input type=\"password\" class=\"form-control\" <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-orange-color\">id=\"pwd\" placeholder=\"Enter password\"<\/mark> name=\"pswd\"&gt;\n            <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-orange-color\">&lt;div id=\"errorPwd\"&gt;&lt;\/div&gt;<\/mark>\n        &lt;\/div&gt;\n            &lt;div class=\"form-check mb-3\"&gt;\n            &lt;label class=\"form-check-label\"&gt;\n            &lt;input class=\"form-check-input\" type=\"checkbox\" name=\"remember\"&gt; Remember me\n            &lt;\/label&gt;\n        &lt;\/div&gt;\n            &lt;button <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-orange-color\">type=\"button\" onClick=\"frmSubmit();\"<\/mark> class=\"btn btn-primary\"&gt;Submit&lt;\/button&gt;\n        &lt;\/form&gt;\n        <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-orange-color\">&lt;script&gt;\n            function frmSubmit(){\n                const frmName     = document.getElementById(\"name\").value;\n                const frmPwd      = document.getElementById(\"pwd\").value;\n\n                errorName.innerHTML = \"\";\n                errorPwd.innerHTML  = \"\";\n\n                if(frmName == \"\"){\n                    errorName.innerHTML = \"&lt;p&gt;\uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter Your Name)&lt;\/p&gt;\";\n                } else if(frmPwd == \"\"){\n                    errorPwd.innerHTML = \"&lt;p&gt;\ud328\uc2a4\uc6cc\ub4dc\ub97c \uc785\ub825\ud558\uc138\uc694(Please Enter Your Password)&lt;\/p&gt;\";\n                }else{\n                    frm.submit();\n                }\n            }\n        &lt;\/script&gt;<\/mark>\n    &lt;\/body&gt;\n&lt;\/html&gt;    \n<\/code><\/pre>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/www.facebook.com\/plugins\/video.php?height=314&#038;href=https%3A%2F%2Fwww.facebook.com%2Fgideonslife01%2Fvideos%2F1364044314305632%2F&#038;show_text=false&#038;width=560&#038;t=0\" width=\"560\" height=\"314\" style=\"border:none;overflow:hidden\" scrolling=\"no\" frameborder=\"0\" allowfullscreen=\"true\" allow=\"autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share\" allowFullScreen=\"true\"><\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>\uc720\ud6a8\uc131 \uac80\uc0ac\ub780 \ub370\uc774\ud130 \uc804\uc1a1\uc744 \ud558\uae30 \uc704\ud574 \ud3fc\uc758 \uc785\ub825 \ud544\ub4dc\uc5d0 \uac12\uc744 \uc785\ub825\ud560 \ub54c \uac12\uc774 \uc815\uc0c1\uc801\uc73c\ub85c \uc785\ub825\ub418\uc5c8\ub294\uc9c0 \ud655\uc778 \ud558\uae30 \uc704\ud55c \ubd80\ubd84 \uc785\ub2c8\ub2e4.\uc774\ub7ec\ud55c \ud3fc\uc758 \uc720\ud6a8\uc131\uac80\uc0ac\ub294 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\ub97c \uc774\uc6a9\ud569\ub2c8\ub2e4.\uc624\ub80c\uc9c0\uc0c9 \uceec\ub7ec\uc758 \ucf54\ub4dc\ub294 \uc0c8\ub86d\uac8c \ucd94\uac00\ub41c \ucf54\ub4dc \uc785\ub2c8\ub2e4.Validation is the part to ensure that the value is entered normally when you enter the value in the input field of the form to transfer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-376","post","type-post","status-publish","format-standard","hentry","category-php","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=376"}],"version-history":[{"count":15,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/376\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/376\/revisions\/441"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}