Posted on by

Generating Unique Member IDs for New Registrations

I often get questions about how to set up member IDs in Participants Database. It is possible to use the built in “id” or “private_id” fields, but in most cases, you’ll want to be able to generate your member IDs yourself according to your desired format.

I am providing a working example plugin, which you can customize to your purpose, or use it as-is. It just assigns a number as the ID, and whenever a new record comes in, it gives it the next number.

You can change the part that assigns the new ID with your own formula for determining the member ID if you want to use a custom format.

Setting Up the Member ID Field

The member ID field needs to be set up in your Participants Database fields. You can set it as a “text-line” field or “numeric” if you just want consecutive numbers for your IDs. Configure it to be included in the signup form and marked as “read only.” The plugin code hides the field in the signup form so it can set the member ID in the background.

The ID field must be configured to be included in the signup form in order for the new ID value to be saved when the new record is saved.

The Plugin

I’m including a plugin that sets up a simple member ID field functionality: it starts with 1000 and then every new record added after that gets the next number in the sequence. You can easily adapt this to other kinds of member ID schemes if you know how to do that in php.

Download this plugin by clicking on the filename at the bottom of the code window. It will take you to a page where you can download the zip file. The zip file can be easily installed on your site by using the “Plugins/Add New” item in the admin, then clicking on the “Add New” button at the top of the page.

Be sure to edit the plugin file so that the $id_field variable has the name of your Member ID field.

This plugin will also automatically add a member ID to records that don’t have one when they are updated.

3 thoughts on “Generating Unique Member IDs for New Registrations

  1. Hi,
    this looks very usefull. Just to be sure I understand this correctly, I’d like to check:

    1. I’ve already got a text-line field that uses a 4-digit membership code, that starts at 0001 and now is on 1064.. Will the plugin respect the existing numbers lower than 1000? And should I alter the starting number in line 17 to 1065, or will the plugin recognize the existing highest number?

    2. the name of this existing field is ‘lidnummer’. Should I change the ‘member_id’ part in all the relevant lines, like ‘member_id_is_not_unique’ to ‘lidnummer_is_not_unique’, or is there a better way?

    I have a related question: is there an option to also autofill an existing date field (start date membership) with the date of registration (other than the date_recorded field) as a hidden field on the signup form (without updating existing emtpy fields, like the member_id-plugin does).

    Thank for a reply one of these days (it’s not an urgent matter).

    1. #1: the plugin checks for the chronologically last record created to determine the starting point for the next number, but that may not work if you’ve already got ID numbers and the highest number isn’t in the last record to be created. You could possibly alter the function so it looks for the highest id number (instead of the last created record), but that will only work if the field’s data type is numeric.

      #2 If your ID field has a different name the only place you need to change the code is in the initial assignment of the $id_field variable on line 12

      It is not possible to have a date field be a hidden field in the signup form. What you need to do is very similar to the code here, it would write the date of the registration to your date field when a new registration comes in.

    2. Oh, one more thing…it will probably work if your IDs are consecutive because the plugin will keep incrementing the ID it is considering until it gets one that is not in the DB.

Leave a Reply
You have to agree to the comment policy.

3 thoughts on “Generating Unique Member IDs for New Registrations

  1. Hi,
    this looks very usefull. Just to be sure I understand this correctly, I’d like to check:

    1. I’ve already got a text-line field that uses a 4-digit membership code, that starts at 0001 and now is on 1064.. Will the plugin respect the existing numbers lower than 1000? And should I alter the starting number in line 17 to 1065, or will the plugin recognize the existing highest number?

    2. the name of this existing field is ‘lidnummer’. Should I change the ‘member_id’ part in all the relevant lines, like ‘member_id_is_not_unique’ to ‘lidnummer_is_not_unique’, or is there a better way?

    I have a related question: is there an option to also autofill an existing date field (start date membership) with the date of registration (other than the date_recorded field) as a hidden field on the signup form (without updating existing emtpy fields, like the member_id-plugin does).

    Thank for a reply one of these days (it’s not an urgent matter).

    1. #1: the plugin checks for the chronologically last record created to determine the starting point for the next number, but that may not work if you’ve already got ID numbers and the highest number isn’t in the last record to be created. You could possibly alter the function so it looks for the highest id number (instead of the last created record), but that will only work if the field’s data type is numeric.

      #2 If your ID field has a different name the only place you need to change the code is in the initial assignment of the $id_field variable on line 12

      It is not possible to have a date field be a hidden field in the signup form. What you need to do is very similar to the code here, it would write the date of the registration to your date field when a new registration comes in.

    2. Oh, one more thing…it will probably work if your IDs are consecutive because the plugin will keep incrementing the ID it is considering until it gets one that is not in the DB.

Leave a Reply
You have to agree to the comment policy.