spivurno
5/21/2015 - 4:01 PM

GP Unique ID // Gravity Perks // Populate Unique ID via Dynamic Population

GP Unique ID // Gravity Perks // Populate Unique ID via Dynamic Population

<?php
/**
 * GP Unique ID // Gravity Perks // Populate Unique ID via Dynamic Population
 * 
 * INSTRUCTIONS:
 * 
 * 1 - Copy and paste this code into your theme's functions.php file.
 * 2 - Add a Single Line Text field (or any field you would like to populate with a unique ID) to your form.
 * 3 - Enable the "Allow field to be populated dynamically" setting under the Advanced tab on the field settings for the newly created field.
 * 4 - Set "uid" as the value for the Paramater Name setting (screenshot: https://gwiz.io/2HhtBTa). 
 */
add_filter( 'gform_field_value_uid', function( $value, $field ) {
	if( function_exists( 'gp_unique_id' ) ) {
		$field[ gp_unique_id()->perk->key( 'length' ) ] = 9;
		$value = gp_unique_id()->get_unique( $field->formId, $field );
	}
	return $value;
}, 10, 2 );