gpppw_word_count (JS)
Description
Filter the calculated word count for the current field on the frontend.
This filter must be used with its PHP counterpart to handle filtering the word count on the frontend.
Usage
gform.addFilter( 'gpppw_word_count', 'my_custom_function' );
Parameters
wordCount int
The calculated word count.
text string
The string of words to be counted.
gwppw \GWPayPerWord
The current instance of the GWPayPerWord object.
ppwField object
An array of options used to handle the Pay Per Word functionality.
formId int
The current form object.
Examples
Pay Per Character
Change Pay Per Word’s behavior to charge per character instead of per word. This snippet must be paired with its PHP counterpart.
/**
* Gravity Perks // Pay Per Word // Surprise, Pay Per Character! (JS)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*
* This snippet requires the PHP counterpart gpppw-pay-per-character.php
*/
gform.addFilter( 'gpppw_word_count', function( wordCount, text, gwppw, ppwField, formId ) {
// Pay per character instead of words.
return [...text].length;
} );
Split Words on Specific Characters
In this example, Pay Per Word splits words on periods, underscores, and asterisks. This snippet must be paired with its PHP counterpart.
/**
* Gravity Perks // Pay Per Word // Split Words on Specific Characters (JS)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*
* This snippet requires the PHP counterpart gpppw-split-words-on-specific-characters.php
*/
gform.addFilter( 'gpppw_word_count', function( wordCount, text, gwppw, ppwField, formId ) {
// Splits words on periods, underscores, and asterisks.
var words = text.replace( /[\.\_\*]/g, ' ' ).match( /\S+/g );
return words == null ? 0 : words.length;
} );
Since
This filter is available since Gravity Forms Pay Per Word 1.0.6.
All Connections
All Perks
- GF Address Autocomplete
- GF Advanced Calculations
- GF Advanced Phone Field
- GF Advanced Save & Continue
- GF Advanced Select
- GF Auto List Field
- GF Auto Login
- GF Better User Activation
- GF Blocklist
- GF Bookings
- GF Conditional Logic Dates
- GF Conditional Pricing
- GF Copy Cat
- GF Date Time Calculator
- GF Disable Entry Creation
- GF Easy Passthrough
- GF eCommerce Fields
- GF Email Users
- GF Email Validator
- GF Entry Blocks
- GF Expand Textareas
- GF File Renamer
- GF File Upload Pro
- GF Inventory
- GF Limit Checkboxes
- GF Limit Dates
- GF Limit Submissions
- GF Live Preview
- GF Media Library
- GF Multi-Page Navigation
- GF Nested Forms
- GF Notification Scheduler
- GF Page Transitions
- GF Pay Per Word
- GF Populate Anything
- GF Post Content Merge Tags
- GF Preview Submission
- GF Price Range
- GF QR Code
- GF Randomizer
- GF Read Only
- GF Reload Form
- GF Submit to Access
- GF Terms Of Service
- GF Unique ID
- GF Word Count