{"id":4023,"date":"2022-01-21T15:23:32","date_gmt":"2022-01-21T15:23:32","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=4023"},"modified":"2022-02-17T07:13:46","modified_gmt":"2022-02-17T07:13:46","slug":"input-int","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/forms\/checking-form-input\/input-int","title":{"rendered":"Input &#8211; Int"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Example<\/h4>\n\n\n\n<p>PHP<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/******************************************\n\/\/******************************************\n\/\/********** VALIDATE INPUT - INT **********\n\/\/******************************************\n\/\/******************************************\nfunction ValidateInputInt($FieldName, &amp;$Error, $OptionsArray)\n{\n  if ($_SERVER&#91;\"REQUEST_METHOD\"] == \"POST\")\n  {\n    if ( ($EnteredValue = filter_var($_POST&#91;$FieldName], FILTER_VALIDATE_INT, $OptionsArray)) !== False )\n    {\n      return($EnteredValue);\n    }\n    else\n    {\n      $Error = \"* Invalid\";  \/\/Or could use \"* Invalid ${FieldName}\";\n      return False;\n    }\n  }\n  else\n  {\n    return False;\n  }\n}\n\n\n$MyInputName_Options =   &#91;\"options\" =&gt; &#91;\n    \"min_range\" =&gt; 1,\n    \"max_range\" =&gt; 12\n  ]];\n$MyInputName = ValidateInputInt(\"MyInputName\", $MyInputName_Error, $MyInputName_Options);\n\n<\/code><\/pre>\n\n\n\n<p>HTML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  Enter value: &lt;input type=\"number\" name=\"MyInputName\" value=\"&lt;?= $_POST&#91;\"MyInputName\"];?>\" min=\"&lt;?=$MyInputName_Options&#91;\"options\"]&#91;\"min_range\"];?>\" max=\"&lt;?=$MyInputName_Options&#91;\"options\"]&#91;\"max_range\"];?>\" >\n  &lt;span class=\"error\">&lt;?= $MyInputName_Error;?>&lt;\/span>\n  &lt;br><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Example PHP HTML<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[313],"tags":[],"class_list":["post-4023","post","type-post","status-publish","format-standard","hentry","category-checking-form-input"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=4023"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4023\/revisions"}],"predecessor-version":[{"id":4027,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4023\/revisions\/4027"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=4023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=4023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=4023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}