Posted on by

Generating Unique Member IDs for New Registrations

Update 1/16/19: this plugin had to be rewritten to work with versions of Participants Database later than 1.8.0.

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 “read only” if you don’t want the user changing it.

The plugin code sets the member ID in the background after the form is submitted so it doesn’t need to be included in the signup form.

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.

39 thoughts on “Generating Unique Member IDs for New Registrations

  1. Hello how are you?
    First of all I would like to thank you for making this material available, it is very useful.
    I would like to know if I have how to define the link of a participant (eg: /? Pdb = 100) to be equal to my column with RG name instead of ID?
    Or did my ID column match the information I import from my RG column?
    Note: I am importing the data through a CSV!

    1. The normal single record link ( ?pdb=100 ) only works with the “id” column of the record. If you want to use a different column to identify the record ( ?rg=13 ), you have to write custom code for that, the plugin does not do this.

      Also, you cannot set the “id” of new records when you import with a CSV. The plugin will ignore the imported id value and automatically assign an “id” value for all new records.

  2. Hi Roland,

    Where is the class “pdb_generate_member_id” called after the signup form is submitted? I want to make a second version of this plugin to change the logic based on an if statement. I need to know where I would put my if statement wherever the generate_member_id class is being called outside of this plugin but I’m unable to find it. Ultimately, I want to change the format of the member ID based on the signup page name however when I call the page name within the plugin it’s unable to work in that context. If I were to point to another version of this plugin where the naming structure is different I think that will be a good work around, assuming I can call the page name where the generate member ID class is being called.

    I hope that all makes sense! I appreciate the help!

    Thanks,
    Kevin

    1. With a plugin like this, the class is declared when all the plugins are initialized. But that doesn’t matter to your question, what is important is what happens when a signup is submitted. When the signup is submitted, the maybe_save_member_id method is called, and you can get the name of the page in that context. In your version of the function, you need to declare global $post; then you can access the values in the post object, and the name of the page will be $post->post_name

  3. Hi Roland, thanks for the great pdb.

    I have the member_id as hidden for use with the signup form ‘Thank you’ message. The member_id won’t then display for the shortcode : [pdb_record template="RO-member" fields="member_id, email"]
    Is there a way to display hidden fields on the single record template? thanks

    1. There’s no easy way to show a hidden field, they stay hidden on the record edit form too.

      If you need the field to be hidden in certain contexts, it’s a lot easier to set the field up as a text or numeric field, then use CSS to hide the field in contexts where you don’t want it seen.

      Another approach is to use a custom template for the pdb_record shortcode that has code that shows the value of the hidden field as a separate element. (instead of trying to make the hidden field visible)

  4. Hi im not too familiar with code so id just like to ask is it possible to instead of just the code being numbers like you described 1000 going up if you could add initials to always be at the beginning?

    like instead of 1000 to 1001 to 1002 and so on
    it would be like MB1000 to MB1001 to MB1002

    If possible could i get an idea as to how i go about doing so in the code edits

    1. The code I provided is meant to be a starting point for your own custom code, so you’ll have to make the changes yourself. It will be a little tricky to do as you ask because the new ID is generated by simply adding 1, but adding text characters to the ID will interfere with that. You will need to split the ID into text and number parts before generating the new ID, then reassemble the ID to be saved. This is on line 112 of the example.

  5. hi i got everything up and working but the member id field is shown on the sign um form and if i hide it the user cant see it upon logging in how do i do this?

    1. I had to completely re-write the plugin I presented in this article, it was out of date. Please replace the one you got before with the one that is now posted here. Thanks!

      1. where is it posted can i get a link or something? Also lt me say thanks for your awesome plugin it was a lifesaver! i think ill be buying some of the extensions soon.

        1. The plugin is available for download by a link at the bottom of the code window. Also here:

          pdb-generate-member-id.php

        2. Alright thanks! and one more thing i’m just wondering if theres any way to create a second form apart from the record_pdb and the list participants form or a way to edit the list form to be like the record form i wanna add just one more private page exclusive to one person upon login but im not sure if its possible?

        3. I’m sorry I don’t quite understand what you are asking for?

          There is something in the product FAQ about directing the user to a different page depending on some value in their record, so that might be helpful.

          https://xnau.com/product_support/participant-login/#product-faq

        4. Sorry about the bad explanation, what im trying to say is. Is there a way to add a second form that can only be viewed after a user is logged in. like how the pdb_record form works?

          i want to add a second page that can be viewed only when logged in, but has info specific to the logged in user, like the pdb_record form but with different info.

          Sorry for all my questions :v

        5. OK, first it’s important to understand that the Participant Login only gives the user access to the Participants Database record, it is not a WordPress login, so there are no other privileges given, such as the ability to view protected content.

          That said, if you are good with php, you can create a custom template that will show a form in addition to the normal one for a user that has gained access to the record. If you look at the template for the [pdb_record] shortcode, you’ll see that it checks for a record ID, and then shows the form if it finds it. You can have it display other things (such as another shortcode) once it has the record ID. This will require some php skills, but it is certainly possible.

        6. Well okay thanks! And god bless ya :)

  6. Hi,

    Thanks for this plugin it is exactly what I needed.
    I just tried implementing this and it all works fine. Only the signup form is not hiding the member id field. Could this be because of an incompatible theme or am I doing something wrong?

    Kind regards,

    1. If you want the member ID field to be hidden, set it up as a hidden field.

      1. Thanks for the quick reply!
        I just set the field to hidden. Doing this also makes it hidden in the edit record page. And I want participants to be able to see their member id.

        I want the field only to be hidden in the signup form. As I understand it, the hide_id_field() function should take care of this. But it does not seem to be working for me.

        1. Alexander,

          Taking a closer look at this, I realized the plugin I provided was out of date and no longer compatible. I had to re-write it so it will work as expected. You should replace your plugin with the new one I just posted.

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

  8. 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)

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

  10. 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 to Roland Barker Cancel reply

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

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.

39 thoughts on “Generating Unique Member IDs for New Registrations

  1. Hello how are you?
    First of all I would like to thank you for making this material available, it is very useful.
    I would like to know if I have how to define the link of a participant (eg: /? Pdb = 100) to be equal to my column with RG name instead of ID?
    Or did my ID column match the information I import from my RG column?
    Note: I am importing the data through a CSV!

    1. The normal single record link ( ?pdb=100 ) only works with the “id” column of the record. If you want to use a different column to identify the record ( ?rg=13 ), you have to write custom code for that, the plugin does not do this.

      Also, you cannot set the “id” of new records when you import with a CSV. The plugin will ignore the imported id value and automatically assign an “id” value for all new records.

  2. Hi Roland,

    Where is the class “pdb_generate_member_id” called after the signup form is submitted? I want to make a second version of this plugin to change the logic based on an if statement. I need to know where I would put my if statement wherever the generate_member_id class is being called outside of this plugin but I’m unable to find it. Ultimately, I want to change the format of the member ID based on the signup page name however when I call the page name within the plugin it’s unable to work in that context. If I were to point to another version of this plugin where the naming structure is different I think that will be a good work around, assuming I can call the page name where the generate member ID class is being called.

    I hope that all makes sense! I appreciate the help!

    Thanks,
    Kevin

    1. With a plugin like this, the class is declared when all the plugins are initialized. But that doesn’t matter to your question, what is important is what happens when a signup is submitted. When the signup is submitted, the maybe_save_member_id method is called, and you can get the name of the page in that context. In your version of the function, you need to declare global $post; then you can access the values in the post object, and the name of the page will be $post->post_name

  3. Hi Roland, thanks for the great pdb.

    I have the member_id as hidden for use with the signup form ‘Thank you’ message. The member_id won’t then display for the shortcode : [pdb_record template="RO-member" fields="member_id, email"]
    Is there a way to display hidden fields on the single record template? thanks

    1. There’s no easy way to show a hidden field, they stay hidden on the record edit form too.

      If you need the field to be hidden in certain contexts, it’s a lot easier to set the field up as a text or numeric field, then use CSS to hide the field in contexts where you don’t want it seen.

      Another approach is to use a custom template for the pdb_record shortcode that has code that shows the value of the hidden field as a separate element. (instead of trying to make the hidden field visible)

  4. Hi im not too familiar with code so id just like to ask is it possible to instead of just the code being numbers like you described 1000 going up if you could add initials to always be at the beginning?

    like instead of 1000 to 1001 to 1002 and so on
    it would be like MB1000 to MB1001 to MB1002

    If possible could i get an idea as to how i go about doing so in the code edits

    1. The code I provided is meant to be a starting point for your own custom code, so you’ll have to make the changes yourself. It will be a little tricky to do as you ask because the new ID is generated by simply adding 1, but adding text characters to the ID will interfere with that. You will need to split the ID into text and number parts before generating the new ID, then reassemble the ID to be saved. This is on line 112 of the example.

  5. hi i got everything up and working but the member id field is shown on the sign um form and if i hide it the user cant see it upon logging in how do i do this?

    1. I had to completely re-write the plugin I presented in this article, it was out of date. Please replace the one you got before with the one that is now posted here. Thanks!

      1. where is it posted can i get a link or something? Also lt me say thanks for your awesome plugin it was a lifesaver! i think ill be buying some of the extensions soon.

        1. The plugin is available for download by a link at the bottom of the code window. Also here:

          pdb-generate-member-id.php

        2. Alright thanks! and one more thing i’m just wondering if theres any way to create a second form apart from the record_pdb and the list participants form or a way to edit the list form to be like the record form i wanna add just one more private page exclusive to one person upon login but im not sure if its possible?

        3. I’m sorry I don’t quite understand what you are asking for?

          There is something in the product FAQ about directing the user to a different page depending on some value in their record, so that might be helpful.

          https://xnau.com/product_support/participant-login/#product-faq

        4. Sorry about the bad explanation, what im trying to say is. Is there a way to add a second form that can only be viewed after a user is logged in. like how the pdb_record form works?

          i want to add a second page that can be viewed only when logged in, but has info specific to the logged in user, like the pdb_record form but with different info.

          Sorry for all my questions :v

        5. OK, first it’s important to understand that the Participant Login only gives the user access to the Participants Database record, it is not a WordPress login, so there are no other privileges given, such as the ability to view protected content.

          That said, if you are good with php, you can create a custom template that will show a form in addition to the normal one for a user that has gained access to the record. If you look at the template for the [pdb_record] shortcode, you’ll see that it checks for a record ID, and then shows the form if it finds it. You can have it display other things (such as another shortcode) once it has the record ID. This will require some php skills, but it is certainly possible.

        6. Well okay thanks! And god bless ya :)

  6. Hi,

    Thanks for this plugin it is exactly what I needed.
    I just tried implementing this and it all works fine. Only the signup form is not hiding the member id field. Could this be because of an incompatible theme or am I doing something wrong?

    Kind regards,

    1. If you want the member ID field to be hidden, set it up as a hidden field.

      1. Thanks for the quick reply!
        I just set the field to hidden. Doing this also makes it hidden in the edit record page. And I want participants to be able to see their member id.

        I want the field only to be hidden in the signup form. As I understand it, the hide_id_field() function should take care of this. But it does not seem to be working for me.

        1. Alexander,

          Taking a closer look at this, I realized the plugin I provided was out of date and no longer compatible. I had to re-write it so it will work as expected. You should replace your plugin with the new one I just posted.

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

  8. 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)

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

  10. 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 to Roland Barker Cancel reply

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

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.