{"id":457,"date":"2024-04-22T01:10:17","date_gmt":"2024-04-22T01:10:17","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=457"},"modified":"2024-04-22T02:10:33","modified_gmt":"2024-04-22T02:10:33","slug":"form-validation4innerthtmlalert","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/04\/22\/form-validation4innerthtmlalert\/","title":{"rendered":"\ud3fc \uc720\ud6a8\uc131 \ud655\uc778\ud558\uae30(Form validation)(4),innertHTML,alert()"},"content":{"rendered":"\n<p>\ud3fc \uc720\ud6a8\uc131 \ud655\uc778\uc744 \uc704\ud574 innerHTML\ub300\uc2e0\uc5d0 alert()\uc744 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>\uc544\ub798\uc758 \ucf54\ub4dc\uc5d0\uc11c innerHTM \uc2e4\ud589\ubd80\ubd84\uc740 \ucf54\uba58\ud2b8 \ucc98\ub9ac\ud588\uc2b5\ub2c8\ub2e4.<br>\ub178\ub780\uc0c9\uc740 innerHTML\uc744 \uc704\ud55c \ubd80\ubd84\uc774\uace0  \ub179\uc0c9\uc740 alert()\uc744 \uc704\ud55c \ubd80\ubd84\uc785\ub2c8\ub2e4.<br>document.getElementById(&#8220;[ID]&#8221;).focus();\ub294 autofocus\ub97c \uc704\ud55c \ubd80\ubd84\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<p>You can use alert() instead of innerHTML for form validation.<br>In the code below, the innerHTM execution part has been commented out.<br>The yellow part is for innerHTML and the green part is for alert().<br>document.getElementById(&#8220;[ID]&#8221;).focus(); is for autofocus.<br><\/p>\n\n\n\n<p>\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><a rel=\"noreferrer noopener\" href=\"https:\/\/freelifemakers.org\/lec\/form4-1.php\" target=\"_blank\">https:\/\/freelifemakers.org\/lec\/form4-1.php<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n$fileName = \".\/form_action4.php\";\nif(!is_file($fileName)){\n    $form_action_name = basename($_SERVER&#91;'PHP_SELF']);\n}else{\n    $form_action_name = \".\/form_action4.php\";\n}\n?&gt;\n\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n    &lt;head&gt;\n    \u200b  &lt;title&gt;Bootstrap 5 webform&lt;\/title&gt;\n      &lt;!--\uc774 \ubd80\ubd84\uc740 html\ucf54\uba58\ud2b8 \uc601\uc5ed This part is the html comment area,\ub9c8\uc784\ud0c0\uc785\uc124\uc815 Mime type settings\/\/--&gt;\n      &lt;meta charset=\"utf-8\"&gt;\n      &lt;!-- \ubaa8\ubc14\uc77c\ud3f0 \uc2a4\ud06c\ub9b0 \uc635\uc158 Mobile phone screen options\/\/--&gt;\n      &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt;\n      &lt;!--\ubd80\ud2b8\uc2a4\ud2b8\ub7a95 CDN\ubc29\uc2dd \ub9c1\ud06c Bootstrap 5 CDN method link\/\/--&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\n      &lt;!-- \ud3fc\uccb4\ud06c innerHTML\uacbd\uace0 \uba54\uc2dc\uc9c0 \ucd9c\ub825 --&gt;\n      &lt;!-- Form check innerHTML warning message output \/\/--&gt;\n      &lt;script&gt;\n        function frmSubmit(){\n            \n           \/\/name input box\uc5d0\uc11c \uac12\uc744 \uac00\uc838\uc624\uae30\n           \/\/Get value from name input box\n           const frmName     = document.getElementById(\"name\").value;\n           const frmEmail    = document.getElementById(\"email\").value;                                 \n           const frmPwd      = document.getElementById(\"pwd\").value;\n\n           \/\/\uc774\uba54\uc77c \ubc0f \uc6f9\uc0ac\uc774\ud2b8 \uc720\ud6a8\uc131\uac80\uc0ac\n           \/\/Regular expression for email validation\n           const regex = \/^&#91;\\w-]+(\\.&#91;\\w-]+)*@(&#91;\\w-]+\\.)+&#91;a-zA-Z]{2,3}$\/;\n\n           \/\/\uc815\uaddc\ud45c\ud604\uc2dd\uacfc \ube44\uad50\ud558\uc5ec \uc774\uba54\uc77c\ud14c\uc2a4\ud2b8\n           \/\/Test the email against the regular expression\n           const emailCheck = regex.test(frmEmail); \n\n           \/\/\uc5d0\ub7ec\uba54\uc138\uc9c0 \ucd08\uae30\ud654\n           \/\/Reset error message\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#bc9c0f\" class=\"has-inline-color\">           errorName.innerHTML = \"\";\n           errorEmail.innerHTML = \"\";           \n           errorPwd.innerHTML = \"\";<\/mark>\n           \n           \/\/\uac12\uc758 \uc874\uc7ac \uc5ec\ubd80\uccb4\ud06c ,\uacf5\ubc31\uc774\uba74 \uacbd\uace0\ucc3d \ub744\uc6b0\uae30\n           \/\/Check whether value exists, if blank, display warning window\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            <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-green-color\">alert(\"\uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter Your Name)\");\n            document.getElementById(\"name\").focus();<\/mark>\n            return;\n           }else if(frmEmail == \"\"){\n            \/\/errorEmail.innerHTML =\"&lt;p&gt;Email\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter Your Email)&lt;\/p&gt;\";\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-green-color\">            alert(\"Email\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter Your Email)\");\n            document.getElementById(\"email\").focus();<\/mark>\n            return;\n           }else if(emailCheck == false){   \n            \/\/errorEmail.innerHTML =\"&lt;p&gt;\uc815\ud655\ud55c Email\uc744 \uc785\ub825\ud558\uc138\uc694(Please enter the correct Email)&lt;\/p&gt;\";       \n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-green-color\">            alert(\"\uc815\ud655\ud55c Email\uc744 \uc785\ub825\ud558\uc138\uc694(Please enter the correct Email)\");\n            document.getElementById(\"email\").focus();<\/mark>\n            return;                                   \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<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-green-color\">            alert(\"\ud328\uc2a4\uc6cc\ub4dc\ub97c \uc785\ub825\ud558\uc138\uc694(Please Enter Your Password)\");\n            document.getElementById(\"pwd\").focus();<\/mark>\n            return;           \n           }else{\n            frm.submit();\n           }\n        }\n      &lt;\/script&gt;\n\n    &lt;\/head&gt;\n    &lt;body&gt;\n    &lt;div class=\"container-sm\"&gt;    \n        &lt;!--HTML\ud3fc\uc2dc\uc791 Start HTML form \/\/--&gt;\n        &lt;!--\ud3fc\uc774\ub984 \ucd9c\ub825 Print form name \/\/--&gt;\n        &lt;form id=\"frm\" action=\"&lt;?php echo $form_action_name; ?&gt;\" method=\"post\"&gt;\n        &lt;div class=\"mb-3\"&gt;\n            &lt;label for=\"name\" class=\"form-label\"&gt;\uc774\ub984(Name):&lt;\/label&gt;\n            &lt;input type=\"text\" class=\"form-control\" id=\"name\" placeholder=\"Enter Your Name\" name=\"name\" required&gt;\n            <mark style=\"background-color:rgba(0, 0, 0, 0);color:#bc9c0f\" class=\"has-inline-color\">&lt;div id=\"errorName\"&gt;&lt;\/div&gt;<\/mark>\n        &lt;\/div&gt;\n\n        &lt;div class=\"mb-3\"&gt;\n        &lt;label for=\"email\" class=\"form-label\"&gt;Email:&lt;\/label&gt;\n            &lt;input type=\"text\" class=\"form-control\" id=\"email\" placeholder=\"ID@exmale.com\" name=\"email\" required&gt;\n            <mark style=\"background-color:rgba(0, 0, 0, 0);color:#bc9c0f\" class=\"has-inline-color\">&lt;div id=\"errorEmail\"&gt;&lt;\/div&gt;<\/mark>\n        &lt;\/div&gt;\n\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\" id=\"pwd\" placeholder=\"Enter your password\" name=\"pswd\" required&gt;\n            <mark style=\"background-color:rgba(0, 0, 0, 0);color:#bc9c0f\" class=\"has-inline-color\">&lt;div id=\"errorPwd\"&gt;&lt;\/div&gt;<\/mark>\n        &lt;\/div&gt;        \n\n        &lt;div class=\"mb-3\"&gt;\n            &lt;div class=\"form-check mb-3\"&gt;\n            &lt;label class=\"form-check-label\"&gt;Remember me&lt;\/label&gt;\n            &lt;input class=\"form-check-input\" type=\"checkbox\" name=\"remember\"&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n\n            &lt;button type=\"button\" class=\"btn btn-primary\" onClick=\"frmSubmit();\"&gt;Submit&lt;\/button&gt;\n        &lt;\/form&gt;\n        &lt;!--HTML\ud3fc \ub05d End of HTML form\/\/--&gt;\n    &lt;\/div&gt;    \n    &lt;\/body&gt;\n&lt;\/html&gt;    \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud3fc \uc720\ud6a8\uc131 \ud655\uc778\uc744 \uc704\ud574 innerHTML\ub300\uc2e0\uc5d0 alert()\uc744 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\uc544\ub798\uc758 \ucf54\ub4dc\uc5d0\uc11c innerHTM \uc2e4\ud589\ubd80\ubd84\uc740 \ucf54\uba58\ud2b8 \ucc98\ub9ac\ud588\uc2b5\ub2c8\ub2e4.\ub178\ub780\uc0c9\uc740 innerHTML\uc744 \uc704\ud55c \ubd80\ubd84\uc774\uace0 \ub179\uc0c9\uc740 alert()\uc744 \uc704\ud55c \ubd80\ubd84\uc785\ub2c8\ub2e4.document.getElementById(&#8220;[ID]&#8221;).focus();\ub294 autofocus\ub97c \uc704\ud55c \ubd80\ubd84\uc785\ub2c8\ub2e4. You can use alert() instead of innerHTML for form validation.In the code below, the innerHTM execution part has been commented out.The yellow part is for innerHTML and the green part is [&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-457","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\/457","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=457"}],"version-history":[{"count":4,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}