Copy Unique ID to Another Field

Copy a generated Unique ID value to one or more other fields after entry save.

Instructions

Code

Filename: gpuid-copy-uid-to-another-field.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
 * Gravity Perks // Unique ID // Copy Unique ID to Another Field
 * https://gravitywiz.com/documentation/gravity-forms-unique-id/
 *
 * Instruction Video: https://www.loom.com/share/16fa4ef18bb34299b8ef91fca2085060
 *
 * Copy a generated Unique ID value to one or more other fields after entry save.
 *
 * Plugin Name:  GP Unique ID - Copy Unique ID to Another Field
 * Plugin URI:   https://gravitywiz.com/documentation/gravity-forms-unique-id/
 * Description:  Copy a generated Unique ID value to one or more other fields after entry save.
 * Author:       Gravity Wiz
 * Version:      0.1
 * Author URI:   https://gravitywiz.com/
 */
// update the "123" to your form ID
add_filter( 'gform_entry_post_save_123', function( $entry ) {

	// update "1" to your Unique ID field's field ID
	$uid_field_id = 1;

	// update "2" and "3" to whatever field IDs you would like to copy the unique ID, if you only need one, format it like this: array( 2 )
	$copy_to_field_ids = array( 2, 3 );

	foreach ( $copy_to_field_ids as $copy_to_field_id ) {
		$entry[ $copy_to_field_id ] = $entry[ $uid_field_id ];
	}

	GFAPI::update_entry( $entry );

	return $entry;
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.