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.

9 thoughts on “Generating Unique Member IDs for New Registrations

  1. Hi Roland,
    Very much appreciate this added function as it is ideal for my purpose.
    I am a new user of PDB and still learning as I set it up.
    The website it is in is a subdomain and I have included the full path in the website box below.
    It is functioning properly as far as numbering listings, which I have added both internally and externally.

    I created a field named Member ID [member_id], so I have made no changes to your code, the issue is the Member ID field is appearing in the signup form.

    Not sure what I have missed.

    Thanks in advance for your help.

    1. On the Manage Database Fields page you can configure that field as a “hidden” field so it won’t be seen as a field in the form.

  2. Hi!
    I’m about to use combination of characters of members first name, last name and birthdate. That way I can individualise each member but still have unique ID. How can I access those fields in the form? I have tried to read the documentation but can’t figure out. I need to get information from first_name, last_name, and birthdate (created by me) fields.
    And second, when I use private link to edit member information the member_id field is not hidden. Is there a way to hide that (I can do it with css, but plugin itself has that hiding functionality)?
    -Olli

    1. If you’re using the code in this tutorial, you would put your ID together in the generate_new_member_id method. The $record variable will be an array of all the submitted data, so you can get your values from that.

      For the frontend edit record form, you should set the “member_id” field to be “read-only” so the user can’t change it. If you don’t want them to see it, then place the member_id field in a group that is only visible to administrators. (has “admin” checked in the field group definition)

  3. Where would i find the plugin for member id’s please?
    It says: “Download this plugin by clicking on the filename at the bottom of the code window”. Where is this “code window”?

    Thank you.

    1. In the article, there is a window that shows the code for the plugin. At the bottom of the window is a link: pdb-generate-member-id.php Click on that to get to the code’s host page, from there you can download the plugin as a zip file.

      Installing a Plugin from a Gist zip file

  4. 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.

9 thoughts on “Generating Unique Member IDs for New Registrations

  1. Hi Roland,
    Very much appreciate this added function as it is ideal for my purpose.
    I am a new user of PDB and still learning as I set it up.
    The website it is in is a subdomain and I have included the full path in the website box below.
    It is functioning properly as far as numbering listings, which I have added both internally and externally.

    I created a field named Member ID [member_id], so I have made no changes to your code, the issue is the Member ID field is appearing in the signup form.

    Not sure what I have missed.

    Thanks in advance for your help.

    1. On the Manage Database Fields page you can configure that field as a “hidden” field so it won’t be seen as a field in the form.

  2. Hi!
    I’m about to use combination of characters of members first name, last name and birthdate. That way I can individualise each member but still have unique ID. How can I access those fields in the form? I have tried to read the documentation but can’t figure out. I need to get information from first_name, last_name, and birthdate (created by me) fields.
    And second, when I use private link to edit member information the member_id field is not hidden. Is there a way to hide that (I can do it with css, but plugin itself has that hiding functionality)?
    -Olli

    1. If you’re using the code in this tutorial, you would put your ID together in the generate_new_member_id method. The $record variable will be an array of all the submitted data, so you can get your values from that.

      For the frontend edit record form, you should set the “member_id” field to be “read-only” so the user can’t change it. If you don’t want them to see it, then place the member_id field in a group that is only visible to administrators. (has “admin” checked in the field group definition)

  3. Where would i find the plugin for member id’s please?
    It says: “Download this plugin by clicking on the filename at the bottom of the code window”. Where is this “code window”?

    Thank you.

    1. In the article, there is a window that shows the code for the plugin. At the bottom of the window is a link: pdb-generate-member-id.php Click on that to get to the code’s host page, from there you can download the plugin as a zip file.

      Installing a Plugin from a Gist zip file

  4. 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.