Put this code into theme’s functions.php: ( for Ninja Forms 2.9.x )
function unique_code_submission( $data, $field_id ) {
global $uniqueCode;
if ( "string" !== gettype( $uniqueCode ) )
$uniqueCode = uniqid();
/* here goes your code to populate a field */
return $data;
}
add_filter( 'ninja_forms_field', 'unique_code_submission', 10, 2 );
Within above function you will have a unique, 13 characters long code in $uniqueCode
global variable. This code will be generated once only, when the filter is triggered first time. More information about ninja_forms_field
filter: here.
UPDATE: for Ninja Forms 3.0 and up:
function unique_code_submission( $fields ) {
$uniqueCode = uniqid();
/* here goes your code to populate a field. For example:
let's populate hidden field, which has key value of
'hidden_1492812363939' */
$index = 0;
while ( 0 <= $index ) {
++$index;
if ( 'hidden_1492812363939' == $fields[ $index-1 ][ 'key' ] ) {
$fields[ $index-1 ][ 'value' ] = $uniqueCode;
$index = -1;
}
}
return $fields;
}
add_filter( 'ninja_forms_display_fields', 'unique_code_submission', 10, 1 );