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.

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

  1. Hi Roland. I’m running into a complex situation and I wonder if you might have a solution. I’m modifying a custom template “pdb-record-custom” and it checks if the user logged in and allows them to edit based on a record id. I have that record id printing just fine with:

    $record_id = Participants_Db::get_record_id_by_term(‘wp_user_login’, $current_user->user_login);
    echo $record_id;

    How might I then print a specific value using this same record id? The field is “job_category” which I need from the same record id in order to customize the form further.
    Thank you.

    1. You would use the get_participant method like this:

      $record = Participants_Db::get_participant($record_id);

      That will give you an associative array indexed by the field name, you can get any value in the record then.

      1. That just returns “Array”

        $current_user = wp_get_current_user();
        if ( $current_user->ID ) {
        	$type = Participants_Db::get_participant($record_id);
        	echo $type;
        	if ($type == ‘faculty’) {
        		echo do_shortcode( ‘[pdb_record tabs=true template=custom record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
        	} else if ($type == ‘staff’) {
        		echo do_shortcode( ‘[pdb_record tabs=true template=custom groups="main,contact,links" record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
        	} else if ($type == ‘researcher’) {
        		echo do_shortcode( ‘[pdb_record tabs=true template=custom groups="main,contact,links,research" record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
        	} else if ($type == ‘student’) {
        		echo do_shortcode( ‘[pdb_record tabs=true template=custom groups="main,contact,links,research" record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
        	} else {
        		echo do_shortcode( ‘You must log in to edit your record’ );
        	}
        } else {
        	echo ‘You must log in to edit your record’;
        }

        So you can see this shortcode then sends them to the full custom template. I know, i’m probably overcomplicating this… but it was working great until I added the require_login

        1. Yes if you dump it to the screen, that’s what you see. The data is in there, you just need to access it as an array.

        2. I see…. so then what code would pull a specific field value from this array? Btw, thank you so much for the quick responses…

        3. Get a specific value by using the field name as the index: $record[‘fieldname’]

          Basic php: Arrays

        4. Thanks, Roland. I found the solution. I’ll print here in case it could help someone else:

          $type_user = Participants_Db::get_participant($record_id);
          $type = $type_user[“job_category”];

          if ($type == ‘faculty’) {
          echo do_shortcode( ‘[pdb_record tabs=true template=custom record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
          }

  2. Hi there, before everybody tries for ages (ask me!), the script above is NOT working. Please try this instead:

    if ( $this->participant_values[‘type’] === ‘player’ ) {

    echo do_shortcode( ‘[pdb_record groups="common, player"]‘ );
    }
    elseif ( $this->participant_values[‘type’] === ‘parents’ ) {
    echo do_shortcode( ‘[pdb_record groups="common, parents"]‘ );
    }
    else{
    echo “No output, sorry”;
    }

    [[Do not forget to put it into these tags (after php) : ]]

    You can expand it with more elseif, if you want.
    Everything else do the way its written above.

    See here for my source:
    https://wordpress.org/support/topic/problem-using-post-post_name-as-default-value/
    Many Thanks to @eljailer!!!

    1. Hi lureki,

      While I appreciate you giving us another way to do this, it is not true that the code I provided doesn’t work. It may not have worked for you, but that doesn’t mean it won’t work for others. It certainly works for me in my tests.

  3. Hello Roland!
    Thank you for supporting people like you do here! awesome plugin and awesome customer service!!!
    I want to be able to put a “EDIT” button in my pdb-single template that I created based on your tutorials and help which, by the way, works perfectly.

    I tried following this tutorial but I cannot make it happen.

    This is the code of my pdb-single template where I want to put a “EDIT” link at the top, that takes the user to the same record and being able to edit all the info.

    And THANKSSSS

    participant_id ) : ?>

    participant_values[‘type’] ) {

    case ‘company-registration-form’:
    echo do_shortcode( ‘[pdb_single groups="main"]‘ );
    break;

    case ‘property-registration’:
    echo do_shortcode( ‘[pdb_single groups="properties"]‘ );
    break;

    case ‘bank-account-registration’:
    echo do_shortcode( ‘[pdb_single groups="bank_accounts"]‘ );
    break;
    }

    ?>

    1. Take a look at this page, it is for the list template, but you can do the same thing in a single template.

      Adding an Edit Link to the Frontend List

      1. Hi Roland,
        I tried, but I get something at the end of the record that says [admin_record_link] and nothing else.

        Here is the code I used: https://goo.gl/E89fei

        You could modify it if you want :)
        Thanks a lot!!!

        1. sorry, that line was something else, what I mean is that I don’t get anything, just the regular record with no editing capabilities and no link to edit either

        2. The code to add the edit link has to go in the template your are using to actually display the single record….not the one you are using to determine which fields are shown.

        3. I’m a little lost. The code I sent to you is the code to show the record details based on a value of a field. I thought this code must go there.

          Can you give me pointers in how to proceed? I’m just stuck!

        4. Hi Bruce,

          You’ll need another custom template for your single record, which will be used to display the single record. So in the custom template you have, you have three single record shortcodes. Each one of those shortcodes will need to use your new single record template (let’s say it
          s called “edit-link”) with something like:

          echo do_shortcode('[pdb_single template="edit-link"]');

          of course, you need to add your groups attribute to that.

          In the new template, you place the code to produce the edit link, that code needs to go in the loop so it can place the link on the correct field when it’s getting printed. Look at how it is done in the example, it will be similar in the single record template.

          This stuff does require an understanding of php and how these scripts work, I can’t explain all of it, just give you pointers.

  4. Hi,
    I’m trying to get the above code to work.
    I have confirmed that correct template is running by seeing unique echo commands print out on the website page. I’m running a simplified template file to try isolate what’s not working.

    From what I can tell the problem lies in the assignment statement:
    $type = $this->participant_record[‘website’]; //one of the fields in my record
    echo “type = “ . $type . “”;

    There’s something wrong with this statement because $type is empty is always empty.

    1. This is hard to answer definitively without more info. The $this->participant_values property is only available in a Participants Database record form template (in case you’re trying to access that property in another context). Next, of course, you should verify that the record you’re looking at has a value for that field (obvious, but when debugging, it’s never good to make untested assumptions).

      If you set up a “default” value for the field you’re testing, you will get that value if there is no value in the record if that helps.

    2. Hi Roland,
      Thank-you for responding to my comment and I apologize for my tardy reply.
      I managed to get the above code to work by instead using the PDb_Template class you provided. A very nice resource indeed so Kudos to you and your team for this. I’ve inserted my code at the bottom of the reply (i.e. or will try to do this).

      Of course motivation for all of this development is to support two similar but different databases. Not having them distinctly separate complicates the development process. An additional question that surfaced for me on this front is how to provide to separate distinct Email responses?

      Thank-you and Regards,
      Charles

      <?php
      $this_swrecord = new PDb_Template($this);

      /* debug code
      echo "”;
      //$this_swrecord->print_field(‘website’);
      echo “”;
      echo “Next last line reached”;
      echo “”;
      echo “Try the getvalue function”;
      echo “”;
      */

      $type = $this_swrecord->get_value(‘db_type’);
      /* more debug code
      echo “type = ” . $type;
      echo “”;
      echo “Try an If statement”;
      echo “”;
      */

      if (stripos($type, ‘org’) === FALSE) {
      echo do_shortcode(‘[pdb_record groups="common, individual"]‘);
      //echo “This is NOT an org record!”;
      } else {
      echo do_shortcode(‘[pdb_record groups="common, organization"]‘);
      //echo “This is an org record!”;
      }
      ?>

      1. For the emails, it is possible to use a filter to change the email according to a value in the record, there is a filter called pdb-receipt_email_template where you can alter the email content before it goes out.

        A perhaps more elegant solution is offered by the Email Expansion Kit add-on.

  5. Hi Roland,
    Firstly, thanks for a great plugin.

    For the pdb_record I am trying to have users enter both pid and their email in order to show their record.

    I have been looking through the documentation, but haven’t found anything. Maybe I am missing it.

    Hope you can point me in the right direction.

    Thanks.

    /jens

    1. Take a look at the Participant Login add-on, it gives you several options for setting up a kind of login for people to access their record.

  6. Roland, I am trying to create a prototype where a user enters a date and the next x dates are calculated then, using a different plugin, show hide content based on the dates.

    I’m thinking if I can store just one date in the Participant Database, I can retrieve it based on user login id (i.e. email)

    Seems like this template might be the one to start with. True?

    Also, right now I am calculating dates in PHP h, could that be done in the database?

    Thanks

    1. HI Alan,

      While I’m not sure I understand what you’re trying to accomplish, I will point out that this tutorial is not for finding which record to show, but only which template to use. In this case, which record is shown is determined by the URL.

      You are looking for a way to find a record based on the logged-in user’s info, right? Take a look at this page, it will give you some ideas on that: Using Participants Database with WordPress Users

  7. Hello… Mr Roland…
    It been more than a week now that am trying to run the above code on my website to show two records… I followed your procedure word after word….
    But the code won’t run, instead, it copies itself on my Web page..
    Please what could I have possibly omitted?? I have verified the code thoroughly and it exactly as yours…
    Please help me… Thanks for your reply

    1. I can’t tell what is going wrong from your description, so here are the things to check. First, make sure you understand how custom template work by reading this article. If you have the file (with the name pdb-record-usertype.php) uploaded to the correct location, then the template will be used if you have the shortcode [pdb_record template=usertype] on the page. When that page is opened with the correct link (it must have the “pid” code) you will see the fields of the editable record.

      1. thannks for your reply. mr. roland but it really not working for me…
        $type = $this->participant_record[‘type’];
        switch ( $type ) {
        case ‘desingers_imo’:
        echo do_shortcode(‘[pdb_record groups="students,mothers"']);
        break;
        case ‘player’:
        echo do_shortcode(‘[pdb_record groups="sick,healthy"']);
        break
        }
        this code is copied back to my web page when i run the [pdb_record template=usertype]. i put up my template file in the correct destination path.
        please dont really know wat is wrong..it more than a month now that am looking for solutions… thanks for your reply

        1. When looking a problems with custom templates, the first thing to do is make sure the template is actually in use. There are several ways to do this, I will often add a class name to the wrapper div that lets me know the special template is in effect. If you have debugging on, you will see the path to the template in the HTML so you can verify which template is getting used there also.

          Once you are certain your template is in use, and it is still not giving the expected result, you can begin to look at the template code itself to make sure it is working. With something like this, you can have it print the value of your $type variable to make sure it’s getting the expected value. Then, you need to make sure that your comparison values will match the $type value.

          Also, of course, make sure the php code in your custom template is inside the php tags. This is basic syntax, you’ll see errors or code printed to the screen if you get the syntax wrong.

        2. Thanks for your prompt reply…. I have followed your guide and now am stock on the error..don’t know how to handle it… I do not know much of code :Notice: undefined property :PDb_record :: $participant_record in my template. On line 6….thanks for your favourable reply…

        3. The page must be accessed with a URL that includes the private ID. Without it, the shortcode does not know which record to open. The URL usually comes from the email sent to the user, which includes the private ID for that user’s record.

  8. Thank you for your answer, I did not see it immediately.

    I picked up a similar code from your repository but used an if loop. In effect, we used $this->participant_valuesin this code and it worked. I adapted your code for my case.

    Thanks again,
    Best regards

  9. Hello Roland,

    Thank you for your prompt response.
    I modified the shortcode in my previous code and followed your advice. It still does not work.

    I did some tests:

    – I changed the variable $type by something else thinking it could be already used elsewhere.
    – I use another participant_record
    – I add a step to the switch (case”) to know if my variable $typetestvar was filled with the record participant I want.

    Now I can see that the problem is at $typetestvar = $this-> participant_record [‘type1’];
    because it is empty and show the last message don’t work.

    Do you have an idea ?
    Thanks in advance and have a nice weekend,
    Best regards,

    last edit: https://gist.github.com/Donma28/be6b9addfae7a141f2211acc9283be31

    1. The property you want to use is $this->participant_values

  10. Hello Mr Roland,

    I have a small problem with this code. Could you help me please?

    https://gist.github.com/Donma28/be6b9addfae7a141f2211acc9283be31

    I took example on your tutorial above and I just modified the values of the shortcode as well as added an additional box

    When I use the shortcode [pdb_record tabs = "true" template = usertype] I have nothing that appears on my page. Do you have an idea ?

    I take this opportunity to ask another question
    Is it possible to adapt this code for the shortcode [pdb_single] so that the right groups are displayed according to the record and not the user who looks at the record.

    I hope I have been clear, my English is not very good please excuse me.

    Thank you very much in advance for any help you can give me.
    Regards

    1. First, if you are using a custom template, you should not use the “tabs=true” attribute in the shortcode. Also, don’t put spaces around the =. So your shortcode should be:

      [pdb_record template=usertype]

      Now, your template will be used to show the record.

      Setting up a similar custom template for the pdb_single shortcode is the same, you just need to use the correct name for your custom template, then change all the shortcodes in the custom template to be pdb_single.

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.

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

  1. Hi Roland. I’m running into a complex situation and I wonder if you might have a solution. I’m modifying a custom template “pdb-record-custom” and it checks if the user logged in and allows them to edit based on a record id. I have that record id printing just fine with:

    $record_id = Participants_Db::get_record_id_by_term(‘wp_user_login’, $current_user->user_login);
    echo $record_id;

    How might I then print a specific value using this same record id? The field is “job_category” which I need from the same record id in order to customize the form further.
    Thank you.

    1. You would use the get_participant method like this:

      $record = Participants_Db::get_participant($record_id);

      That will give you an associative array indexed by the field name, you can get any value in the record then.

      1. That just returns “Array”

        $current_user = wp_get_current_user();
        if ( $current_user->ID ) {
        	$type = Participants_Db::get_participant($record_id);
        	echo $type;
        	if ($type == ‘faculty’) {
        		echo do_shortcode( ‘[pdb_record tabs=true template=custom record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
        	} else if ($type == ‘staff’) {
        		echo do_shortcode( ‘[pdb_record tabs=true template=custom groups="main,contact,links" record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
        	} else if ($type == ‘researcher’) {
        		echo do_shortcode( ‘[pdb_record tabs=true template=custom groups="main,contact,links,research" record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
        	} else if ($type == ‘student’) {
        		echo do_shortcode( ‘[pdb_record tabs=true template=custom groups="main,contact,links,research" record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
        	} else {
        		echo do_shortcode( ‘You must log in to edit your record’ );
        	}
        } else {
        	echo ‘You must log in to edit your record’;
        }

        So you can see this shortcode then sends them to the full custom template. I know, i’m probably overcomplicating this… but it was working great until I added the require_login

        1. Yes if you dump it to the screen, that’s what you see. The data is in there, you just need to access it as an array.

        2. I see…. so then what code would pull a specific field value from this array? Btw, thank you so much for the quick responses…

        3. Get a specific value by using the field name as the index: $record[‘fieldname’]

          Basic php: Arrays

        4. Thanks, Roland. I found the solution. I’ll print here in case it could help someone else:

          $type_user = Participants_Db::get_participant($record_id);
          $type = $type_user[“job_category”];

          if ($type == ‘faculty’) {
          echo do_shortcode( ‘[pdb_record tabs=true template=custom record_id="'. Participants_Db::get_record_id_by_term('wp_user_login',$current_user->user_login) .'"]‘ );
          }

  2. Hi there, before everybody tries for ages (ask me!), the script above is NOT working. Please try this instead:

    if ( $this->participant_values[‘type’] === ‘player’ ) {

    echo do_shortcode( ‘[pdb_record groups="common, player"]‘ );
    }
    elseif ( $this->participant_values[‘type’] === ‘parents’ ) {
    echo do_shortcode( ‘[pdb_record groups="common, parents"]‘ );
    }
    else{
    echo “No output, sorry”;
    }

    [[Do not forget to put it into these tags (after php) : ]]

    You can expand it with more elseif, if you want.
    Everything else do the way its written above.

    See here for my source:
    https://wordpress.org/support/topic/problem-using-post-post_name-as-default-value/
    Many Thanks to @eljailer!!!

    1. Hi lureki,

      While I appreciate you giving us another way to do this, it is not true that the code I provided doesn’t work. It may not have worked for you, but that doesn’t mean it won’t work for others. It certainly works for me in my tests.

  3. Hello Roland!
    Thank you for supporting people like you do here! awesome plugin and awesome customer service!!!
    I want to be able to put a “EDIT” button in my pdb-single template that I created based on your tutorials and help which, by the way, works perfectly.

    I tried following this tutorial but I cannot make it happen.

    This is the code of my pdb-single template where I want to put a “EDIT” link at the top, that takes the user to the same record and being able to edit all the info.

    And THANKSSSS

    participant_id ) : ?>

    participant_values[‘type’] ) {

    case ‘company-registration-form’:
    echo do_shortcode( ‘[pdb_single groups="main"]‘ );
    break;

    case ‘property-registration’:
    echo do_shortcode( ‘[pdb_single groups="properties"]‘ );
    break;

    case ‘bank-account-registration’:
    echo do_shortcode( ‘[pdb_single groups="bank_accounts"]‘ );
    break;
    }

    ?>

    1. Take a look at this page, it is for the list template, but you can do the same thing in a single template.

      Adding an Edit Link to the Frontend List

      1. Hi Roland,
        I tried, but I get something at the end of the record that says [admin_record_link] and nothing else.

        Here is the code I used: https://goo.gl/E89fei

        You could modify it if you want :)
        Thanks a lot!!!

        1. sorry, that line was something else, what I mean is that I don’t get anything, just the regular record with no editing capabilities and no link to edit either

        2. The code to add the edit link has to go in the template your are using to actually display the single record….not the one you are using to determine which fields are shown.

        3. I’m a little lost. The code I sent to you is the code to show the record details based on a value of a field. I thought this code must go there.

          Can you give me pointers in how to proceed? I’m just stuck!

        4. Hi Bruce,

          You’ll need another custom template for your single record, which will be used to display the single record. So in the custom template you have, you have three single record shortcodes. Each one of those shortcodes will need to use your new single record template (let’s say it
          s called “edit-link”) with something like:

          echo do_shortcode('[pdb_single template="edit-link"]');

          of course, you need to add your groups attribute to that.

          In the new template, you place the code to produce the edit link, that code needs to go in the loop so it can place the link on the correct field when it’s getting printed. Look at how it is done in the example, it will be similar in the single record template.

          This stuff does require an understanding of php and how these scripts work, I can’t explain all of it, just give you pointers.

  4. Hi,
    I’m trying to get the above code to work.
    I have confirmed that correct template is running by seeing unique echo commands print out on the website page. I’m running a simplified template file to try isolate what’s not working.

    From what I can tell the problem lies in the assignment statement:
    $type = $this->participant_record[‘website’]; //one of the fields in my record
    echo “type = “ . $type . “”;

    There’s something wrong with this statement because $type is empty is always empty.

    1. This is hard to answer definitively without more info. The $this->participant_values property is only available in a Participants Database record form template (in case you’re trying to access that property in another context). Next, of course, you should verify that the record you’re looking at has a value for that field (obvious, but when debugging, it’s never good to make untested assumptions).

      If you set up a “default” value for the field you’re testing, you will get that value if there is no value in the record if that helps.

    2. Hi Roland,
      Thank-you for responding to my comment and I apologize for my tardy reply.
      I managed to get the above code to work by instead using the PDb_Template class you provided. A very nice resource indeed so Kudos to you and your team for this. I’ve inserted my code at the bottom of the reply (i.e. or will try to do this).

      Of course motivation for all of this development is to support two similar but different databases. Not having them distinctly separate complicates the development process. An additional question that surfaced for me on this front is how to provide to separate distinct Email responses?

      Thank-you and Regards,
      Charles

      <?php
      $this_swrecord = new PDb_Template($this);

      /* debug code
      echo "”;
      //$this_swrecord->print_field(‘website’);
      echo “”;
      echo “Next last line reached”;
      echo “”;
      echo “Try the getvalue function”;
      echo “”;
      */

      $type = $this_swrecord->get_value(‘db_type’);
      /* more debug code
      echo “type = ” . $type;
      echo “”;
      echo “Try an If statement”;
      echo “”;
      */

      if (stripos($type, ‘org’) === FALSE) {
      echo do_shortcode(‘[pdb_record groups="common, individual"]‘);
      //echo “This is NOT an org record!”;
      } else {
      echo do_shortcode(‘[pdb_record groups="common, organization"]‘);
      //echo “This is an org record!”;
      }
      ?>

      1. For the emails, it is possible to use a filter to change the email according to a value in the record, there is a filter called pdb-receipt_email_template where you can alter the email content before it goes out.

        A perhaps more elegant solution is offered by the Email Expansion Kit add-on.

  5. Hi Roland,
    Firstly, thanks for a great plugin.

    For the pdb_record I am trying to have users enter both pid and their email in order to show their record.

    I have been looking through the documentation, but haven’t found anything. Maybe I am missing it.

    Hope you can point me in the right direction.

    Thanks.

    /jens

    1. Take a look at the Participant Login add-on, it gives you several options for setting up a kind of login for people to access their record.

  6. Roland, I am trying to create a prototype where a user enters a date and the next x dates are calculated then, using a different plugin, show hide content based on the dates.

    I’m thinking if I can store just one date in the Participant Database, I can retrieve it based on user login id (i.e. email)

    Seems like this template might be the one to start with. True?

    Also, right now I am calculating dates in PHP h, could that be done in the database?

    Thanks

    1. HI Alan,

      While I’m not sure I understand what you’re trying to accomplish, I will point out that this tutorial is not for finding which record to show, but only which template to use. In this case, which record is shown is determined by the URL.

      You are looking for a way to find a record based on the logged-in user’s info, right? Take a look at this page, it will give you some ideas on that: Using Participants Database with WordPress Users

  7. Hello… Mr Roland…
    It been more than a week now that am trying to run the above code on my website to show two records… I followed your procedure word after word….
    But the code won’t run, instead, it copies itself on my Web page..
    Please what could I have possibly omitted?? I have verified the code thoroughly and it exactly as yours…
    Please help me… Thanks for your reply

    1. I can’t tell what is going wrong from your description, so here are the things to check. First, make sure you understand how custom template work by reading this article. If you have the file (with the name pdb-record-usertype.php) uploaded to the correct location, then the template will be used if you have the shortcode [pdb_record template=usertype] on the page. When that page is opened with the correct link (it must have the “pid” code) you will see the fields of the editable record.

      1. thannks for your reply. mr. roland but it really not working for me…
        $type = $this->participant_record[‘type’];
        switch ( $type ) {
        case ‘desingers_imo’:
        echo do_shortcode(‘[pdb_record groups="students,mothers"']);
        break;
        case ‘player’:
        echo do_shortcode(‘[pdb_record groups="sick,healthy"']);
        break
        }
        this code is copied back to my web page when i run the [pdb_record template=usertype]. i put up my template file in the correct destination path.
        please dont really know wat is wrong..it more than a month now that am looking for solutions… thanks for your reply

        1. When looking a problems with custom templates, the first thing to do is make sure the template is actually in use. There are several ways to do this, I will often add a class name to the wrapper div that lets me know the special template is in effect. If you have debugging on, you will see the path to the template in the HTML so you can verify which template is getting used there also.

          Once you are certain your template is in use, and it is still not giving the expected result, you can begin to look at the template code itself to make sure it is working. With something like this, you can have it print the value of your $type variable to make sure it’s getting the expected value. Then, you need to make sure that your comparison values will match the $type value.

          Also, of course, make sure the php code in your custom template is inside the php tags. This is basic syntax, you’ll see errors or code printed to the screen if you get the syntax wrong.

        2. Thanks for your prompt reply…. I have followed your guide and now am stock on the error..don’t know how to handle it… I do not know much of code :Notice: undefined property :PDb_record :: $participant_record in my template. On line 6….thanks for your favourable reply…

        3. The page must be accessed with a URL that includes the private ID. Without it, the shortcode does not know which record to open. The URL usually comes from the email sent to the user, which includes the private ID for that user’s record.

  8. Thank you for your answer, I did not see it immediately.

    I picked up a similar code from your repository but used an if loop. In effect, we used $this->participant_valuesin this code and it worked. I adapted your code for my case.

    Thanks again,
    Best regards

  9. Hello Roland,

    Thank you for your prompt response.
    I modified the shortcode in my previous code and followed your advice. It still does not work.

    I did some tests:

    – I changed the variable $type by something else thinking it could be already used elsewhere.
    – I use another participant_record
    – I add a step to the switch (case”) to know if my variable $typetestvar was filled with the record participant I want.

    Now I can see that the problem is at $typetestvar = $this-> participant_record [‘type1’];
    because it is empty and show the last message don’t work.

    Do you have an idea ?
    Thanks in advance and have a nice weekend,
    Best regards,

    last edit: https://gist.github.com/Donma28/be6b9addfae7a141f2211acc9283be31

    1. The property you want to use is $this->participant_values

  10. Hello Mr Roland,

    I have a small problem with this code. Could you help me please?

    https://gist.github.com/Donma28/be6b9addfae7a141f2211acc9283be31

    I took example on your tutorial above and I just modified the values of the shortcode as well as added an additional box

    When I use the shortcode [pdb_record tabs = "true" template = usertype] I have nothing that appears on my page. Do you have an idea ?

    I take this opportunity to ask another question
    Is it possible to adapt this code for the shortcode [pdb_single] so that the right groups are displayed according to the record and not the user who looks at the record.

    I hope I have been clear, my English is not very good please excuse me.

    Thank you very much in advance for any help you can give me.
    Regards

    1. First, if you are using a custom template, you should not use the “tabs=true” attribute in the shortcode. Also, don’t put spaces around the =. So your shortcode should be:

      [pdb_record template=usertype]

      Now, your template will be used to show the record.

      Setting up a similar custom template for the pdb_single shortcode is the same, you just need to use the correct name for your custom template, then change all the shortcodes in the custom template to be pdb_single.

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.