(→Parameters) |
|||
| Line 55: | Line 55: | ||
A full list of available initialization options can be found at: | A full list of available initialization options can be found at: | ||
http://roy-jin.appspot.com/jsp/textareaCounter.jsp | http://roy-jin.appspot.com/jsp/textareaCounter.jsp | ||
| + | |||
| + | == Placement == | ||
| + | |||
| + | This code should be placed in the '''functions.php''' file of your active theme. | ||
== Source Code == | == Source Code == | ||
This filter is located in ''common.php'' | This filter is located in ''common.php'' | ||
Revision as of 01:43, 8 November 2011
Description
Use this filter to change the initialization script for the textarea counter script. Can be used to specify different initialization parameters.
Usage
<?php
add_filter("gform_counter_script", "set_counter_script", 10, 4);
?>
You can also target a specific form by adding the form id after the hook name.
<?php
add_filter("gform_counter_script_6", "set_counter_script", 10, 4);
?>
Parameters
$script
- (string) The script (including <script> tag) to be filtered.
$form_id
- (int) ID of current form.
$field_id
- (int) ID of current field.
$maxLength
- (int) Configured max character length.
Examples
This example changes the display format of the counter message to: "XXX characters remaining"
<?php
add_filter("gform_counter_script_187", "set_counter_script", 10, 4);
function set_counter_script($script, $form_id, $field_id, $max_length){
$script = "<script type='text/javascript'>//<![CDATA[\n jQuery(document).ready(function(){" .
"jQuery('#{$field_id}').textareaCount(" .
" {" .
" 'maxCharacterSize': {$max_length}," .
" 'originalStyle': 'ginput_counter'," .
" 'displayFormat' : '#left characters remaining.'" .
" })});" .
"\n//]]></script>";
return $script;
}
?>
A full list of available initialization options can be found at: http://roy-jin.appspot.com/jsp/textareaCounter.jsp
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in common.php