Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save geekontheroad/667d7e5b636eb7c21e7df14cb0d20e8c to your computer and use it in GitHub Desktop.
Save geekontheroad/667d7e5b636eb7c21e7df14cb0d20e8c to your computer and use it in GitHub Desktop.
Add a suffix or prefix to the Gravity forms Live Summary
<!----
* EXAMPLE 1: ADD SUFFIX TO A VALUE IN THE GF LIVE SUMMARY
*
* The below code can be used to add a suffix to any field in the Gravity Forms Summary.
* IMPORTANT: You need the Live Summary for Gravity forms addon with a minimum version of 1.1.14.1 installed
*
* INSTRUCTIONS
* 1. Add a new HTML field to your form and copy the code (including <script> tags) to the html field
* 2. Update the fieldsIds array with a comma separated list of your fields that need a suffix.
* 3. Update the suffix variable to your desired suffix
* 4. Save your form
--->
<script type="text/javascript">
jQuery(document).on('gform_post_render', function(event, form_id, current_page){
gform.addFilter('gotrgf_append_suffix_field_value', function (str, fieldId) {
let fieldIds = [18,22]; // add field ids here separated by a comma
let suffix = " /month"; // add your desired suffix here
if(fieldIds.includes(fieldId)) {
str = suffix;
}
return str;
});
});
</script>
<!----
* EXAMPLE 2: ADD PREFIX TO A VALUE IN THE GF LIVE SUMMARY
*
* The below code can be used to add a prefix to any field in the Gravity Forms Summary.
* IMPORTANT: You need the Live Summary for Gravity forms addon with a minimum version of 1.1.14.1 installed
*
* INSTRUCTIONS
* 1. Add a new HTML field to your form and copy the code below (including <script> tags) to the html field
* 2. Update the fieldsIds array with a comma separated list of your fields that need a prefix.
* 3. Update the prefix variable to your desired prefix
* 4. Save your form
--->
<script type="text/javascript">
jQuery(document).on('gform_post_render', function(event, form_id, current_page){
gform.addFilter('gotrgf_prepend_prefix_field_value', function (str, fieldId) {
let fieldIds = [18,22]; // add field ids here separated by a comma
let prefix = "From: "; // add your desired suffix here
if(fieldIds.includes(fieldId)) {
str = prefix;
}
return str;
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment