{"id":1017,"date":"2025-03-24T14:28:17","date_gmt":"2025-03-24T14:28:17","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/add-text-length-validation-for-the-reviews-on-the-frontend\/"},"modified":"2025-04-03T15:24:38","modified_gmt":"2025-04-03T14:24:38","slug":"add-text-length-validation-for-the-reviews-on-the-frontend","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/add-text-length-validation-for-the-reviews-on-the-frontend\/","title":{"rendered":"Add text length validation for the reviews on the frontend"},"content":{"rendered":"\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-info mb-3\" role=\"alert\"><span class=\"fas fa-info-circle me-2\"><\/span><span class=\"flex-grow-1\">We recommend using the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">Code Snippets<\/a> plugin to add snippets to your site.&nbsp;<\/span><\/div>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_action( &#039;comment_form&#039;, function() {\n    ?&gt;\n    &lt;script&gt;\n    (function() {\n        const form = document.querySelector(&#039;#commentform&#039;);\n        if ( typeof form === &#039;undefined&#039; ) return;\n\n        const textArea = form.querySelector(&#039;textarea#comment&#039;);\n\n        if ( form.hasAttribute(&#039;novalidate&#039;) ) {\n            form.removeAttribute(&#039;novalidate&#039;);\n        }\n        if ( ! form.hasAttribute(&#039;validate&#039;) ) {\n            form.setAttribute(&#039;validate&#039;, &#039;&#039;);\n        }\n\n        if ( typeof textArea !== &#039;undefined&#039; ) {\n            textArea.setAttribute(&#039;minlength&#039;, &#039;20&#039;);\n            textArea.setAttribute(&#039;maxlength&#039;, &#039;2000&#039;);\n        }\n    })();\n    &lt;\/script&gt;\n    &lt;?php\n}, 10, 0 );<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,433],"class_list":["post-1017","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/1017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=1017"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/1017\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=1017"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=1017"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=1017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}