1

I'm trying to source documentation on how to create a unique identifier that can be displayed to the user after form submission and to the admin that also receives the submission.

  1. User submits form
  2. User receives confirmation email with "Your code is 2290"
  3. Admin receives form confirmation "User has signed up with order X and code 2290"

I've found a way to grab sequential numbering from the order of submission but it needs to be a unique code to that specific user

The only thing I thought would be to add some sort of relay of their IP and name

Something like Hashids can convert their IP into a small unique identifier but I'm really unsure how to implement something this complex and would need something simple that I've overlooked that ninja forms allows/provides

2

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_fieldfilter: 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 );
  • Hey Frank, thanks for that! How did you output a 13 digit code from the unique code? Is there a way to change the digit length? I need a 3-6 digit code – Tom Hutchison Apr 20 '17 at 22:42
  • @Tom: If you make the code shorter, it cannot be guaranteed to be unique. Tell me, which version of Ninja Forms, you have. Is it a paid version? With this info, I'll be able to provide better help. – Frank P. Walentynowicz Apr 20 '17 at 23:01
  • Yes it's the paid version and the latest one. I'm using it as a system of payment confirmation - User is given code, code given to me as confirmation of payment and identification – Tom Hutchison Apr 20 '17 at 23:11
  • if you didn't get the above – Tom Hutchison Apr 21 '17 at 2:35
  • @Tom: I've got a new hook to use, which is valid for your version of Ninja Forms. Could you email me ( fpw (at) fw2s.com ) your exported form, so I can work on it, and send it back to you with instructions? – Frank P. Walentynowicz Apr 21 '17 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.