FoxCount

Summary: Dynamically display the number of words or characters entered or remaining in an input or a textarea input element.
Version: 2023-11-01
Prerequisites: PHP 7 minimum
Status: stable
Maintainer: PierreRacine
License: GPL2
Categories: Forms
Users: (view? / edit)
Discussion: FoxCount-Talk?

Questions answered by this recipe

How can I display the number of words or characters already entered or remaining in an input or a textarea input element?

Description

FoxCount provides four new directives:

(:foxcharcount inputname:) and (:foxwordcount inputname:) which count the number of characters or words already entered in an input or a textarea input element.

(:foxremainingchars inputname maxchars:) and (:foxremainingwords inputname maxwords:) which count the remaining number of characters or words to be entered in an input or a textarea input element.

"inputname" is the value the input element or textarea "name" attribute to count the words or characters for.

"maxwords" is the maximum number of words the input element should display. The number of remaining words is simply (maxwords - count of words). Note that the maximum number of words is not enforced on the input or textarea element.

"maxchars" is the maximum number of characters the input element should display. The number of remaining characters is simply (maxchars - count of characters). Note that the maximum number of characters is not enforced on the input or textarea element.

maxchars can also automatically be deduced from the maxlength element attribute (see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/maxlength). In this case the maximum number of characters is enforced on the input or textarea element.

Installation

Copy foxcount.phpΔ to your cookbook folder and add

include_once("$FarmD/cookbook/foxcount.php");

to your local/config.php file.

Note

This recipe will also work with PmWiki default forms not controlled by the Fox recipe.

Change log / Release notes

2023-11-01: First version.

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also

Fox

Contributors

PierreRacine

Comments

See discussion at FoxCount-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.