Posted on by

Showing a Record Edit Form Based on a Value in the Record

When using Participants Database to represent two or more classes of people or things, you sometimes need to customize the frontend edit form so that is only shows the fields that are relevant to the type of record that is getting edited. We can easily do this with a custom template.

If you’re not familiar with the use of custom templates, read this article: Using Participants Database Custom Templates

For our example, we are continuing the example used in “Multiple Databases” with Participants Database where you have a kid’s sports team and you have records for the players and the parents. We want to show a different record edit form for each of the two classes of people.

When someone wants to edit their record, they will typically use either a “private link” or a login page provided by the Particpant Login add-on. The way this works, when they go to their edit record page, we use a custom template to determine what kind of record edit form to show, and then the template invokes the record edit form with the desired parameters. It’s a template that uses shortcodes, as you will see.

As in the example, you have your fields organized into three groups: “contact”, “player” and “parent”. The “contact” group is used for all records and the other two are specific to the type of person. There is a field named “type” that tells us which type the record is for, and we use that to determine which set of field groups to show.

Here is a custom template that does that, it is named pdb-record-usertype.php

To use the template, use this shortcode on your record edit page:

[pdb_record template=usertype]

That’s it! Of course, you’ll need to customize this to your particular situation, but that is the general technique.

57 thoughts on “Showing a Record Edit Form Based on a Value in the Record

  1. Hi Roland,
    First of all, thanks for this fantastic plugin. I run a website for a small not for profit sailing club. I have all our members information stored on the database. Currently for our annual membership renewal I am using a form on another plugin (WPforms) to collect the information and then importing the data into PDB. Its a bit messy and now trying to build a form so members can update their own data and renew their membership. We have two types of membership, Full, for members that have boats and we need to collect quite a bit of information each year, and a social membership for non boat owning members that we only need more basic information. I am trying to build a Multi-page form that on the first page shows name and contact details etc, then page 2, that I want to be specific for the type of membership, which this custom template does for me. The problem I am having is that when using this custom template the Action attribute doesn’t work. I want to go to a third page for payment, GDPR/Privacy fields etc. If I get it working, I will then be looking at your Payments add on. I have tried to create another custom template modifying the default record template and adding this code. I just get critical errors. I’m not a coder so stabbing around a bit in the dark. I have succeeded in the past to edit some of your custom templates to do what I want, but this one is beating me. Can you offer any suggestions?
    Thanks
    David

    1. Well, I can’t comment on your code of course, but I will say that the “action” attribute in the shortcode does not require any special code in the template, it actually has nothing to do with the template. The attribute simply tells the plugin which page to go to after the form is submitted. In a multi-page form, each page is a separate form submission. When the user goes to the next page, the record ID is used to open the form on that page.

      Try setting up your form using built-in templates at first so that you can be sure the basic multi-page form is working, then if you need to use a custom template, add that in.

      1. Thanks for the prompt reply. I apologise for my delayed reply to you, my initial reply failed to post as I had put too much detail in and it was getting too late to redo it. I removed the custom template attribute from the shortcode and Multipage worked as expected. To double check I re-added the attribute with template=default and again multipage worked as expected. I seem to recall the default record template has something about the Submit button in it. I was hoping to try adding that to the custom template to see if that made any difference, but I have lost FTP access to my site today.

      2. Hi Roland,
        I have just realised my mistake. I was putting the action attribute in the shortcode on the second page. I now realise it needs to be in the shortcode contained in the custom template. This really opens up what I can do with my forms now as I was using quite a bit of conditional logic in the WPforms form I want to replace.
        Sorry for wasting your time,
        David

        1. Glad you figured it out!

  2. Also, I read the article on how to use a short code for the template pdb-record-usertype.php. The shortcode is missing. What is the shortcode? Thx.

    This is what the article cites:

    To use the template, use this shortcode on your record edit page:

    No record was found.

    1. Yes, sorry about that…issues with displaying the shortcode, which I have fixed.

      The shortcode you’re looking for is

      [pdb_record template=usertype]

  3. Hey Roland. I’ve noticed that when I click that should lead to a edit records page, in the notification email, that I’m lead to a log-in page that request user name and password. I’ve created many fictitious accounts, all using the same email address, but never created a password. Whose password and user name is the database requesting?

    1. The plugin is not doing this, this is configured on your site somehow. Maybe your page is private? The plugin does not have a login.

  4. Roland, also I have created a “type” hidden field on each of the three classes of users on my database (Participants Info {type}, Business/Services, {type2}, and Church/Organization {type3}. I have also created a page using the [pdb_record] short code, but the return link still brings up records from all three classes. Much of the info in each class is required. So, a person from one particular class is asked to fill in the required info for all three classes.

    I once stumbled upon a setting that would allow corrections in one class to be saved even if the required info in the other two classes was not supplied. But, I can’t seem to find it again. Can you please help me out with this? It was my second best option, because I still cannot get the database to sent specialized fields to the appropriate class user.

    Thanks.

  5. Roland, I have three classes for my database, namely Participant Info, Business/Services, and Church/Organizations. Would you please look over my code please. Thanks,

    participant_id ) : ?>

  6. Hey Roland,
    Thanks again for a solid plugin!
    When a user fills in the form, they get the email saying they can “You may complete your registration with additional information or update your information by visiting this private link at any time: https://DOMAIN.com/FORM-PAGE/?pid=P12345.”

    1) How do I make it so when they return to that page, the form field are prefilled with previous info they submitted?
    2) I understand there may be privacy concerns if falling into the wrong hands, but for long forms, it can be annoying having to re-fill in all the info, and not being sure what has been filled prior..

    Thanks for your suggestions.
    Cheers

    1. Found it!

      [pdb_record] is the perfect page!

      As you’ve written:
      ‘This short only displays when accessed with a URL including the record “private id” number. It allows the user to edit and add to their own record, while others won’t have access to it. A private link to this record can be included in the “thank you” email they will receive on submission.’

      Thanks!

  7. Hello, first I want to tell you that your plugin is excellent !!

    I have a query, I am making a map with tables and chairs in which the user can choose their table, for now I do it with [pdb_record fields = table] where a field appears to complete with the chosen table number. What I want to achieve is instead of the field to fill in to get a “sit here” button that adds the data without putting the number. This is possible?
    thank you very much in advance and
    pd: how beautiful is the place where you live, someday I will go!

    1. This sort of thing is possible, but it will certainly require some javascript skills to manage the user’s interaction with your graphical interface. You can easily use a Custom Template to set up the display of your graphical interface and also embed the needed javascript. The actual data should probably go into a hidden field. This field would be updated with the table number when the user clicks.

      Also, you may need some way to make some tables unavailable if they are full.

      1. there is a shortcode that changes a value, example [pdb_record set_field = "table = 2"] ?
        thanks for your answer!

        1. No, you would need to do something like that in a custom template.

  8. Hi,

    I used the code example from your article and edited it. This is my version:

    participant_values[‘form_type’];
    /*
     * now, show the record edit form for that type
     */
    switch ( $form_type ) {
       case ‘won’:
          echo do_shortcode(‘[pdb_record groups="main,wot1,wot2,wot3,wot4,wot5,wot6,wot7,wot8,wot9,wot10,wot11"]‘);
          break;
       case ‘tes’:
          echo do_shortcode(‘[pdb_record groups="main,testimonies"]‘);
          break;
       case ‘pdb_images’:
          echo do_shortcode(‘[pdb_record groups="main,image_uploading"]‘);
          break;
    }

    I’m not sure what else I need to do. I am assuming that $form_type refers to the database field name that holds that information, which is form_type. The values in that field are either ‘won’, ‘tes’ or ‘pdb_images’.

    Can you see any errors in how I have edited it? I’m no coder, so I am dabbling blindly here!

    1. You’re right, the first line of the code in the example (you got the syntax wrong there) is to get a specific value from the current record. The word in quotes is the name of the field you want to get the value from. Using your code, the name of the field you’re looking at is “form_type” so the line should be:

      $form_type = $this->participant_values[‘form_type’];
  9. HI Roland,

    Would this work if I had set up my database to work with WordPress users?

    I have followed the instructions and got so far, but I get the following error:

    Notice: Undefined variable: form_type in /var/www/new.kresy-siberia.org/public_html/wp-content/participants-database-templates/pdb-record-usertype.php on line 11

    Notice: Undefined variable: form_type in /var/www/new.kresy-siberia.org/public_html/wp-content/participants-database-templates/pdb-record-usertype.php on line 14

    Notice: Undefined variable: form_type in /var/www/new.kresy-siberia.org/public_html/wp-content/participants-database-templates/pdb-record-usertype.php on line 17

    Those errors relate to the page names that are set as the form type. Checking the database I can see that the values are correct in there.

    Reading on one of the previous comments here, I see that you previously stated “The page must be accessed with a URL that includes the private ID.”. My page is accessed via the record slug. Could this be an issue?

    Shelley

    1. I have another article that goes into detail about working with WordPress users: Participants Database and WordPress Users

      I can’t comment on the issues you’re having without seeing the code, but it looks like you are not assigning the $form_type variable correctly.

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

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

57 thoughts on “Showing a Record Edit Form Based on a Value in the Record

  1. Hi Roland,
    First of all, thanks for this fantastic plugin. I run a website for a small not for profit sailing club. I have all our members information stored on the database. Currently for our annual membership renewal I am using a form on another plugin (WPforms) to collect the information and then importing the data into PDB. Its a bit messy and now trying to build a form so members can update their own data and renew their membership. We have two types of membership, Full, for members that have boats and we need to collect quite a bit of information each year, and a social membership for non boat owning members that we only need more basic information. I am trying to build a Multi-page form that on the first page shows name and contact details etc, then page 2, that I want to be specific for the type of membership, which this custom template does for me. The problem I am having is that when using this custom template the Action attribute doesn’t work. I want to go to a third page for payment, GDPR/Privacy fields etc. If I get it working, I will then be looking at your Payments add on. I have tried to create another custom template modifying the default record template and adding this code. I just get critical errors. I’m not a coder so stabbing around a bit in the dark. I have succeeded in the past to edit some of your custom templates to do what I want, but this one is beating me. Can you offer any suggestions?
    Thanks
    David

    1. Well, I can’t comment on your code of course, but I will say that the “action” attribute in the shortcode does not require any special code in the template, it actually has nothing to do with the template. The attribute simply tells the plugin which page to go to after the form is submitted. In a multi-page form, each page is a separate form submission. When the user goes to the next page, the record ID is used to open the form on that page.

      Try setting up your form using built-in templates at first so that you can be sure the basic multi-page form is working, then if you need to use a custom template, add that in.

      1. Thanks for the prompt reply. I apologise for my delayed reply to you, my initial reply failed to post as I had put too much detail in and it was getting too late to redo it. I removed the custom template attribute from the shortcode and Multipage worked as expected. To double check I re-added the attribute with template=default and again multipage worked as expected. I seem to recall the default record template has something about the Submit button in it. I was hoping to try adding that to the custom template to see if that made any difference, but I have lost FTP access to my site today.

      2. Hi Roland,
        I have just realised my mistake. I was putting the action attribute in the shortcode on the second page. I now realise it needs to be in the shortcode contained in the custom template. This really opens up what I can do with my forms now as I was using quite a bit of conditional logic in the WPforms form I want to replace.
        Sorry for wasting your time,
        David

        1. Glad you figured it out!

  2. Also, I read the article on how to use a short code for the template pdb-record-usertype.php. The shortcode is missing. What is the shortcode? Thx.

    This is what the article cites:

    To use the template, use this shortcode on your record edit page:

    No record was found.

    1. Yes, sorry about that…issues with displaying the shortcode, which I have fixed.

      The shortcode you’re looking for is

      [pdb_record template=usertype]

  3. Hey Roland. I’ve noticed that when I click that should lead to a edit records page, in the notification email, that I’m lead to a log-in page that request user name and password. I’ve created many fictitious accounts, all using the same email address, but never created a password. Whose password and user name is the database requesting?

    1. The plugin is not doing this, this is configured on your site somehow. Maybe your page is private? The plugin does not have a login.

  4. Roland, also I have created a “type” hidden field on each of the three classes of users on my database (Participants Info {type}, Business/Services, {type2}, and Church/Organization {type3}. I have also created a page using the [pdb_record] short code, but the return link still brings up records from all three classes. Much of the info in each class is required. So, a person from one particular class is asked to fill in the required info for all three classes.

    I once stumbled upon a setting that would allow corrections in one class to be saved even if the required info in the other two classes was not supplied. But, I can’t seem to find it again. Can you please help me out with this? It was my second best option, because I still cannot get the database to sent specialized fields to the appropriate class user.

    Thanks.

  5. Roland, I have three classes for my database, namely Participant Info, Business/Services, and Church/Organizations. Would you please look over my code please. Thanks,

    participant_id ) : ?>

  6. Hey Roland,
    Thanks again for a solid plugin!
    When a user fills in the form, they get the email saying they can “You may complete your registration with additional information or update your information by visiting this private link at any time: https://DOMAIN.com/FORM-PAGE/?pid=P12345.”

    1) How do I make it so when they return to that page, the form field are prefilled with previous info they submitted?
    2) I understand there may be privacy concerns if falling into the wrong hands, but for long forms, it can be annoying having to re-fill in all the info, and not being sure what has been filled prior..

    Thanks for your suggestions.
    Cheers

    1. Found it!

      [pdb_record] is the perfect page!

      As you’ve written:
      ‘This short only displays when accessed with a URL including the record “private id” number. It allows the user to edit and add to their own record, while others won’t have access to it. A private link to this record can be included in the “thank you” email they will receive on submission.’

      Thanks!

  7. Hello, first I want to tell you that your plugin is excellent !!

    I have a query, I am making a map with tables and chairs in which the user can choose their table, for now I do it with [pdb_record fields = table] where a field appears to complete with the chosen table number. What I want to achieve is instead of the field to fill in to get a “sit here” button that adds the data without putting the number. This is possible?
    thank you very much in advance and
    pd: how beautiful is the place where you live, someday I will go!

    1. This sort of thing is possible, but it will certainly require some javascript skills to manage the user’s interaction with your graphical interface. You can easily use a Custom Template to set up the display of your graphical interface and also embed the needed javascript. The actual data should probably go into a hidden field. This field would be updated with the table number when the user clicks.

      Also, you may need some way to make some tables unavailable if they are full.

      1. there is a shortcode that changes a value, example [pdb_record set_field = "table = 2"] ?
        thanks for your answer!

        1. No, you would need to do something like that in a custom template.

  8. Hi,

    I used the code example from your article and edited it. This is my version:

    participant_values[‘form_type’];
    /*
     * now, show the record edit form for that type
     */
    switch ( $form_type ) {
       case ‘won’:
          echo do_shortcode(‘[pdb_record groups="main,wot1,wot2,wot3,wot4,wot5,wot6,wot7,wot8,wot9,wot10,wot11"]‘);
          break;
       case ‘tes’:
          echo do_shortcode(‘[pdb_record groups="main,testimonies"]‘);
          break;
       case ‘pdb_images’:
          echo do_shortcode(‘[pdb_record groups="main,image_uploading"]‘);
          break;
    }

    I’m not sure what else I need to do. I am assuming that $form_type refers to the database field name that holds that information, which is form_type. The values in that field are either ‘won’, ‘tes’ or ‘pdb_images’.

    Can you see any errors in how I have edited it? I’m no coder, so I am dabbling blindly here!

    1. You’re right, the first line of the code in the example (you got the syntax wrong there) is to get a specific value from the current record. The word in quotes is the name of the field you want to get the value from. Using your code, the name of the field you’re looking at is “form_type” so the line should be:

      $form_type = $this->participant_values[‘form_type’];
  9. HI Roland,

    Would this work if I had set up my database to work with WordPress users?

    I have followed the instructions and got so far, but I get the following error:

    Notice: Undefined variable: form_type in /var/www/new.kresy-siberia.org/public_html/wp-content/participants-database-templates/pdb-record-usertype.php on line 11

    Notice: Undefined variable: form_type in /var/www/new.kresy-siberia.org/public_html/wp-content/participants-database-templates/pdb-record-usertype.php on line 14

    Notice: Undefined variable: form_type in /var/www/new.kresy-siberia.org/public_html/wp-content/participants-database-templates/pdb-record-usertype.php on line 17

    Those errors relate to the page names that are set as the form type. Checking the database I can see that the values are correct in there.

    Reading on one of the previous comments here, I see that you previously stated “The page must be accessed with a URL that includes the private ID.”. My page is accessed via the record slug. Could this be an issue?

    Shelley

    1. I have another article that goes into detail about working with WordPress users: Participants Database and WordPress Users

      I can’t comment on the issues you’re having without seeing the code, but it looks like you are not assigning the $form_type variable correctly.

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

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