gform_honeypot_input_name

The gform_honeypot_input_name filter can be used to customize the name attribute of the hidden honeypot field.

Important: This filter is executed when the form is displayed and again during submission. To ensure the honeypot works correctly, it must return the same name in both cases.

Usage

add_filter( 'gform_honeypot_input_name', 'your_function_name', 10, 2 );

Parameters

ParameterTypeDescription
$namestringThe honeypot input name.
$formFormThe form being rendered or validated.

Examples

Hash and cache name.

This example takes the default name (e.g. input_1), appends the form ID and Gravity Forms version number to it, and then uses the WordPress wp_hash function to hash it using your site salts, creating an input name that is unique to both your form and site. It also caches the name for two days.

add_filter( 'gform_honeypot_input_name', function ( $name, $form ) {
	$form_id   = absint( rgar( $form, 'id' ) );
	$cache_key = 'gform_honeypot_input_name_' . $form_id;

	$cached_name = GFCache::get( $cache_key );
	if ( ! empty( $cached_name ) ) {
		return $cached_name;
	}

	$name = wp_hash( $name . '_' . $form_id . '_' . GFForms::$version );
	GFCache::set( $cache_key, $name, true, DAY_IN_SECONDS * 2 );

	return $name;
}, 10, 2 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

return apply_filters( 'gform_honeypot_input_name', $name, $form );

This filter is located in \Gravity_Forms\Gravity_Forms\Honeypot\GF_Honeypot_Handler::get_input_name() in includes/honeypot/class-gf-honeypot-handler.php

Since

The gform_honeypot_input_name filter was added in Gravity Forms version 2.9.16.