{"id":6517,"date":"2014-05-27T13:56:12","date_gmt":"2014-05-27T17:56:12","guid":{"rendered":"http:\/\/localhost\/documentation\/"},"modified":"2019-09-23T11:46:42","modified_gmt":"2019-09-23T15:46:42","slug":"gform_counter_script","status":"publish","type":"post","link":"https:\/\/docs.gravityforms.com\/gform_counter_script\/","title":{"rendered":"gform_counter_script"},"content":{"rendered":"<h2 id=\"h-description\">Description<\/h2>\n<p>Use this filter to change the initialization script for the textarea counter script. Can be used to specify different initialization parameters.<\/p>\n<h2 id=\"h-usage\">Usage<\/h2>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nadd_filter( 'gform_counter_script', 'set_counter_script', 10, 5 );\r\n<\/pre>\n<p>You can also target a specific form by adding the form id after the hook name.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nadd_filter( 'gform_counter_script_6', 'set_counter_script', 10, 5 );\r\n<\/pre>\n<h2 id=\"h-parameters\">Parameters<\/h2>\n<ul>\n<li><strong>$script<\/strong> <a data-autolink=\"autolink_string\" href=\"\/string\">string<\/a>\n<p>The script (including &lt;script> tag) to be filtered.<\/p>\n<\/li>\n<li>\n<p><strong>$form_id<\/strong> <a data-autolink=\"autolink_integer\" href=\"\/integer\">integer<\/a><\/p>\n<p>ID of current form.<\/p>\n<\/li>\n<li>\n<p><strong>$input_id<\/strong> <a data-autolink=\"autolink_string\" href=\"\/string\">string<\/a><\/p>\n<p>ID of HTML input.<\/p>\n<\/li>\n<li>\n<p><strong>$maxLength<\/strong> <a data-autolink=\"autolink_integer\" href=\"\/integer\">integer<\/a><\/p>\n<p>Configured max character length.<\/p>\n<\/li>\n<li>\n<p><strong>$field<\/strong> <a data-autolink=\"autolink_gf_field\" href=\"\/gf_field\">GF_Field<\/a><\/p>\n<p>The Field object.<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"h-examples\">Examples<\/h2>\n<p>This example changes the display format of the counter message to: &#8220;XXX characters remaining&#8221;<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nadd_filter( 'gform_counter_script_187', 'set_counter_script', 10, 5 );\r\nfunction set_counter_script( $script, $form_id, $input_id, $max_length, $field ) {\r\n    $script = &quot;jQuery('#{$input_id}').textareaCount(&quot; .\r\n                &quot;    {&quot; .\r\n                &quot;    'maxCharacterSize': {$max_length},&quot; .\r\n                &quot;    'originalStyle': 'ginput_counter',&quot; .\r\n                &quot;    'displayFormat' : '#left characters remaining.'&quot; .\r\n                &quot;    });&quot;;\r\n    return $script;\r\n}\r\n<\/pre>\n<p>A full list of available initialization options can be found at:<\/p>\n<p><a href=\"https:\/\/github.com\/LeadSift\/jquery-textareaCounter\">https:\/\/github.com\/LeadSift\/jquery-textareaCounter<\/a><\/p>\n<h2 id=\"h-placement\">Placement<\/h2>\n<p>This code should be placed in the <a href=\"http:\/\/codex.wordpress.org\/Theme_Development#Functions_File\">functions.php file<\/a> of your active theme.<\/p>\n<h2 id=\"h-source-code\">Source Code<\/h2>\n<p>This filter is located in GFFormDisplay::get_counter_init_script() in <em>form_display.php<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"Description.","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_autodraft_ids":[],"_sb_is_suggestion_mode":false,"_sb_show_suggestion_boards":false,"_sb_show_comment_boards":false,"_sb_suggestion_history":"","_sb_update_block_changes":"","_is_real_time_mode":false,"_realtime_collaborators":"","footnotes":"","jetpack_post_was_ever_published":false,"cf_checklist_status":[]},"categories":[12813],"tags":[],"class_list":["post-6517","post","type-post","status-publish","format-standard","hentry","category-other-fields","wpautop"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>gform_counter_script - Gravity Forms Documentation<\/title>\n<meta name=\"description\" content=\"Use this filter to change the initialization script for the textarea counter script. Can be used to specify different initialization parameters.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/docs.gravityforms.com\/gform_counter_script\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"gform_counter_script\" \/>\n<meta property=\"og:description\" content=\"Use this filter to change the initialization script for the textarea counter script. Can be used to specify different initialization parameters.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/docs.gravityforms.com\/gform_counter_script\/\" \/>\n<meta property=\"og:site_name\" content=\"Gravity Forms Documentation\" \/>\n<meta property=\"article:published_time\" content=\"2014-05-27T17:56:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-23T15:46:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/docs.gravityforms.com\/wp-content\/uploads\/2023\/08\/gf-docs-default-v3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"544\" \/>\n\t<meta property=\"og:image:height\" content=\"288\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Justin Pakes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@gravityforms\" \/>\n<meta name=\"twitter:site\" content=\"@gravityforms\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Justin Pakes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/gform_counter_script\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/gform_counter_script\\\/\"},\"author\":{\"name\":\"Justin Pakes\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#\\\/schema\\\/person\\\/8a88745ec2ee5bc1bb24eea8634bf376\"},\"headline\":\"gform_counter_script\",\"datePublished\":\"2014-05-27T17:56:12+00:00\",\"dateModified\":\"2019-09-23T15:46:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/gform_counter_script\\\/\"},\"wordCount\":213,\"publisher\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#organization\"},\"articleSection\":[\"Other Fields\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/gform_counter_script\\\/\",\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/gform_counter_script\\\/\",\"name\":\"gform_counter_script - Gravity Forms Documentation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#website\"},\"datePublished\":\"2014-05-27T17:56:12+00:00\",\"dateModified\":\"2019-09-23T15:46:42+00:00\",\"description\":\"Use this filter to change the initialization script for the textarea counter script. Can be used to specify different initialization parameters.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/gform_counter_script\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/docs.gravityforms.com\\\/gform_counter_script\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/gform_counter_script\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/docs.gravityforms.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"gform_counter_script\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#website\",\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/\",\"name\":\"Gravity Forms Documentation\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/docs.gravityforms.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#organization\",\"name\":\"Gravity Forms\",\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/gravity-forms-2020-logo-stacked.png\",\"contentUrl\":\"https:\\\/\\\/docs.gravityforms.com\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/gravity-forms-2020-logo-stacked.png\",\"width\":392,\"height\":515,\"caption\":\"Gravity Forms\"},\"image\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/gravityforms\",\"http:\\\/\\\/@gravityforms.com\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#\\\/schema\\\/person\\\/8a88745ec2ee5bc1bb24eea8634bf376\",\"name\":\"Justin Pakes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g\",\"caption\":\"Justin Pakes\"},\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/author\\\/pakes\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"gform_counter_script - Gravity Forms Documentation","description":"Use this filter to change the initialization script for the textarea counter script. Can be used to specify different initialization parameters.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/docs.gravityforms.com\/gform_counter_script\/","og_locale":"en_US","og_type":"article","og_title":"gform_counter_script","og_description":"Use this filter to change the initialization script for the textarea counter script. Can be used to specify different initialization parameters.","og_url":"https:\/\/docs.gravityforms.com\/gform_counter_script\/","og_site_name":"Gravity Forms Documentation","article_published_time":"2014-05-27T17:56:12+00:00","article_modified_time":"2019-09-23T15:46:42+00:00","og_image":[{"width":544,"height":288,"url":"https:\/\/docs.gravityforms.com\/wp-content\/uploads\/2023\/08\/gf-docs-default-v3.png","type":"image\/png"}],"author":"Justin Pakes","twitter_card":"summary_large_image","twitter_creator":"@gravityforms","twitter_site":"@gravityforms","twitter_misc":{"Written by":"Justin Pakes","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/docs.gravityforms.com\/gform_counter_script\/#article","isPartOf":{"@id":"https:\/\/docs.gravityforms.com\/gform_counter_script\/"},"author":{"name":"Justin Pakes","@id":"https:\/\/docs.gravityforms.com\/#\/schema\/person\/8a88745ec2ee5bc1bb24eea8634bf376"},"headline":"gform_counter_script","datePublished":"2014-05-27T17:56:12+00:00","dateModified":"2019-09-23T15:46:42+00:00","mainEntityOfPage":{"@id":"https:\/\/docs.gravityforms.com\/gform_counter_script\/"},"wordCount":213,"publisher":{"@id":"https:\/\/docs.gravityforms.com\/#organization"},"articleSection":["Other Fields"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/docs.gravityforms.com\/gform_counter_script\/","url":"https:\/\/docs.gravityforms.com\/gform_counter_script\/","name":"gform_counter_script - Gravity Forms Documentation","isPartOf":{"@id":"https:\/\/docs.gravityforms.com\/#website"},"datePublished":"2014-05-27T17:56:12+00:00","dateModified":"2019-09-23T15:46:42+00:00","description":"Use this filter to change the initialization script for the textarea counter script. Can be used to specify different initialization parameters.","breadcrumb":{"@id":"https:\/\/docs.gravityforms.com\/gform_counter_script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/docs.gravityforms.com\/gform_counter_script\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/docs.gravityforms.com\/gform_counter_script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/docs.gravityforms.com\/"},{"@type":"ListItem","position":2,"name":"gform_counter_script"}]},{"@type":"WebSite","@id":"https:\/\/docs.gravityforms.com\/#website","url":"https:\/\/docs.gravityforms.com\/","name":"Gravity Forms Documentation","description":"","publisher":{"@id":"https:\/\/docs.gravityforms.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/docs.gravityforms.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/docs.gravityforms.com\/#organization","name":"Gravity Forms","url":"https:\/\/docs.gravityforms.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/docs.gravityforms.com\/#\/schema\/logo\/image\/","url":"https:\/\/docs.gravityforms.com\/wp-content\/uploads\/2020\/01\/gravity-forms-2020-logo-stacked.png","contentUrl":"https:\/\/docs.gravityforms.com\/wp-content\/uploads\/2020\/01\/gravity-forms-2020-logo-stacked.png","width":392,"height":515,"caption":"Gravity Forms"},"image":{"@id":"https:\/\/docs.gravityforms.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/gravityforms","http:\/\/@gravityforms.com"]},{"@type":"Person","@id":"https:\/\/docs.gravityforms.com\/#\/schema\/person\/8a88745ec2ee5bc1bb24eea8634bf376","name":"Justin Pakes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g","caption":"Justin Pakes"},"url":"https:\/\/docs.gravityforms.com\/author\/pakes\/"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pdGaEa-1H7","_links":{"self":[{"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/posts\/6517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/comments?post=6517"}],"version-history":[{"count":1,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/posts\/6517\/revisions"}],"predecessor-version":[{"id":22764,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/posts\/6517\/revisions\/22764"}],"wp:attachment":[{"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/media?parent=6517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/categories?post=6517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/tags?post=6517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}