Posted on by

Adding an Edit Record Link to the Frontend List

Let’s say you want some users who do not have access to the admin section to be able to edit records. You want to show them a list of records that includes a link to a record edit page.

Set Up the Participant Record Page

First make sure your record edit page (known as the Participant Record Page) is properly set up. This is a page which has the [pdb_record] shortcode in it and will therefore show the user’s editable record when properly accessed. Make sure it’s configured in the plugin settings under the Record Form tab: the “Participant Record Page” setting needs to point to your record edit page.

Setting up the Link

You’ll be showing a list of records with a link to edit a record in each listing, so you’ll need to decide what field the link should go on. For this tutorial, we create a new “placeholder” field (on the Manage Database Fields page) and name it “Edit Link” and give it a default value of “Edit.” (The default value can actually be any text you want shown as the clickable text) This column won’t do anything other than provide clickable text. Go to the Manage List Columns Page to add your edit link to the list display.

It’s important that the field you choose for your edit link is not the same field as you have defined as the “Single Record Link Field” in the settings.

The Custom Template

In this article, I am providing an example template that you can use. It is very important that you place that template file in the correct location on your website. Please read Using Participants Database Custom Templates for the details.

The custom template example I provide is named pdb-list-edit-link.php To use the template, add the name of the template to the list shortcode like this: [pdb_list template=edit-link]

How the Code Works

Here is the main loop that generates the list as seen in “pdb-list-default.php”:

<tbody>
<?php while ( $this->have_records() ) : $this->the_record(); // each record is one row ?>
  <tr>
    <?php while( $this->have_fields() ) : $this->the_field(); // each field is one cell ?>
      <td class="<?php echo $this->field->name ?>-field">
        <?php $this->field->print_value() ?>
      </td>
  <?php endwhile; // each field ?>
  </tr>
<?php endwhile; // each record ?>
</tbody>

We need to alter the value of a field before it’s displayed, so that goes inside the second loop, before anything is printed.  The plugin has a convenient way to do that: a template helper class with methods that give us easy ways to work with the field values. We set that up by instantiating the Template class object using the current record object ($this).

Here is the code for a template that shows an edit link for each record in the list. This replaces the code shown above.

<tbody>
<?php while ( $this->have_records() ) : $this->the_record(); // each record is one row ?>
    <?php $record = new PDb_Template($this); ?>
  <tr>
    <?php while( $this->have_fields() ) : $this->the_field(); // each field is one cell ?>
      <td class="<?php echo $this->field->name ?>-field">
        <?php 
        /*
         * put the edit link URL into the link property of the field
         */
        if ($this->field->name == 'edit_link') {
          $this->field->link = $record->get_edit_link();
        }
        $this->field->print_value();
        ?>
      </td>
  <?php endwhile; // each field ?>
  </tr>
<?php endwhile; // each record ?>
</tbody>

The way this works, is for each new record, the Template class is instantiated with that record’s data. Then we start looping through the fields in that record. When the “edit_link” field is getting shown, we make the field clickable by putting the edit link URL into the field’s “link” property. The $record->get_edit_link() method is provided by the template object, and makes getting the correct URL of your record edit page easy.

You can use this technique to add a link to any text or image field in the list. To make a field value clickable, set the “link” property of the field ($this->field) to the URL you want the click to go to. If the field already has a link on it, the new link will replace it.

The get_edit_link() property uses the global setting “Participant Record Page” to determine which page the editable record is shown on. You can also set that in the function itself if for some reason you wanted it to be different for this particular template: $record->get_edit_link('record-edit') if you want to send them to a page with the slug “record-edit.”

The Complete Template

Here is the whole template for you to use if you don’t want to create your own. The link to download it is at the bottom of the code window.

196 thoughts on “Adding an Edit Record Link to the Frontend List

  1. Hello Roland,
    I followed all steps carefuly and link appeared sucessfuly but my changes aren’t saving in the record.

    1. Hi happy to help, but I don’t have enough info to know where it went wrong. When you click the link, do you successfully go to the where you can edit the record? So, then when you edit the record and hit save, what happens? Do you see any messages? How do you know it didn’t change anything?

      1. any modification i did in the records dosn’t appear when i refresh after the change.
        i tried to check the change after update with other browser and i found the change.
        if you need further clarification please let me know.

        1. OK, if you see the new data when you open the page in a new browser, this means that the first browser is caching the page, so you don’t see the change in that browser.

          If you have a plugin installed on your website that changes the browser caching, you should look at that for the cause of the problem. Participants Database does not do anything to browser caching.

  2. Hello! I did all you said in these posts, but I could generate a page in order to edit a record…

    1. If you follow the directions exactly, it will work, so you may need to read the instructions more carefully to make sure you understand them.

  3. Hi Roland,

    Is it possible to add the edit link button to the frontend of a single record as well?

    Thanks

    1. It is very similar to the way the link is added to the list. You need to create a custom template so you can place your edit button. The two things you need to create the link is first instantiate the PDb_Template object then use the get_edit_link() method of the object to get the URL for your link.

      <?php
      $record = new PDb_Template( $this );
      $edit_url = $record->get_edit_link();
      ?>
      <a href="<?php echo $edit_url ?>" >EDIT RECORD</a>

      1. Hi Roland,

        I tried to use the Edit Record template along with the Field Group Tabs but the tabs aren’t working.

        What do you advise for that please?

        1. What is the full shortcode you are using?

        2. this one:

          [pdb_single template=edit-button tabs=true]

        3. OK, what you need to do is add the field groups tabs code to your custom template. It’s not complicated, take a look at this article: Using Field Group Tabs with a Custom Template

        4. You are a star!

          Just added the code: just after <div class="wrap wrap_class ?>”>

          and worked perfectly

          Many thanks for your great help

  4. This is a great plugin that has been working well for years on my site, but today I updated to Version 1.9.7.4 and found that the Edit link was no longer active. On investigation I realised that the pdb-list-default.php file is obsolete and is now pdb-list-edit-link.php, so downloaded and installed it in the templates folder of my theme. However the edit link is still not active. I have not made any other changes e.g. to Participants database settings. My theme is up to date and WP is at 5.7.2. Any thoughts?

    1. Your template is most likely in the incorrect location. First, the update must have deleted your template because it was in the plugins folder.

      You can place the template in the wp-content folder in a folder named “participants-database-templates”.

      wp-content/participants-database-templates/pdb-list-edit-link.php

  5. I added the edit_link to the short-code [pdb-list] and works fine. I get a list of all members. However if I click on the dash-icons I get localhostundefined. What goes wrong?

    1. Make sure you have the “Participant Record Page” configured in the Participants Database settings under the Record Form tab.

  6. Using the edit-record-link I get the record-edit page. I want to skip in this form the personal info fields except the photo-link and want to add a DELETE-button beside the SAVE-button.
    I am looking in the class-file PDb_Init.php but my changes have no effect.
    How can I reach my goals?

    1. I advise you against editing the plugin directly, there are ways to modify how things work without doing that. Take a look at the documentation on how to control which fields are shown in the [pdb_record] shortcode.

      For deleting a record, you may not be able to add a “delete” button as you describe, the plugin doesn’t normally give the user a way to delete a record. You can take a look at this article for some ideas on how to do that:

      Giving the User a Way to Delete Their Own Record

      1. I added a field, named Edit, with the edit_link. This field is shown in the pdb-list.
        But it is also shown in the record-edit form. The latter is not the intention. How can I prevent this?

        1. The edti_link field should be a “placeholder” field, that will prevent it from showing up in the record-edit form.

  7. Two questions.

    1. I am able to display the Edit Link for each PDB record, however when I click on the edit link, it takes me to an empty page that says “No record was found”. I have [pdb_record] on the page and the POST ID added to the Record Form Settings > Participant Record Page”.

    When I click on the link from the list page, the target page shows up with the following URL.
    .example.com/edit-record/?pid=92IC2

    2. On the list page, how do I ensure that only records matching an index field (say userid=1234) are displayed? I want to limit the scope of record list (or display) to the WP users who created them.

    Appreciate your help.

    1. So, if the link is going to the page with the [pdb_record] shortcode, and the URL is properly constructed (looks like it is) then for some reason, the PID is invalid. Are you using the Participant Login plugin with the “One Time Use Private ID” setting? That setting may be incompatible with presenting a list of edit links on the frontend. Also, make sure there is no page caching active on any page with Participants Database shortcodes.

      Second question is aswered in my provious email to you. If you are using the plugin with WP users, don’t try to use the Participant Login add-on as well, they don’t work well together.

  8. Hi Roland
    i follow step by step and new list works perfectly, however if i try to search using default Search short code [pdb_search] it does not search or display requester data

    1. To show the search, use the “search” attribute of the list shortcode like this:

      [pdb_list search=true]

      You don’t need to use the pdb_search shortcode.

  9. Hello Roland,

    I could not download the Custom Template Folder add-on. Anyway, I did add your complete template (pdb-list-edit-link.php) in this location:
    /wp-content/participants-database-templates/

    Edit link page
    [pdb_list template=edit-link]

    Participants record page
    [pdb_record]
    Participants record page shows table of [pdb_record] with no records.
    Edit link page shows table of [pdb_list template=edit-link] with data but without edit link (hyperlink) or edit possibilities.
    I get the same view if I use [pdb_list template=edit-link] and [pdb_record] at the same Participants record page.

    Can you tell me what I have to do?
    Thanks in advance!

    1. What exactly was the problem in downloading the Template Folder plugin?

      If you don’t use the Template Folder plugin, you must place your custom templates in your theme. This is explained here: Using Participants Database Custom Templates. If you put your templates into the plugin folder, they will be deleted when you update thw plugin.

      It sounds like the [pdb_list template=edit-link] shortcode is not using the custom template. Make sure the template is in the correct location. Also, you must edit the template to match the field name you want to use for your link.

      1. Dear Roland,

        Thank you very much for your quick response and support. I don’t know why I couldn’t download the Custom Template Folder add-on yesterday. But today it works fine. After installation I saw two new folders: wp-content/participants-database-templates (this folder was empty) & wp-content/plugins/pdb-custom-templates2 (this folder contains a folder “templates” with a file named “pdb-list-edit-link.php”.
        I copied that file and moved it to wp-content/participants-database-templates.
        After that I added the shortcode of [pdb_list template=edit-link] to the Participant Record Page.
        The Participant Record Page shows now, like in the case of Bostjan Zrimsek (post of June 6 2020), a list of the records but without a link. And I see also an “Export CSV..” and file name for exporting all records of the database.
        If I edit the template text and use the text in your article, then I get a list of records without a hyperlink.
        You wrote that I have to edit the template to match the field name I want to use for my link. Where exactly do I have to change that?

        Thanks in advance!

        1. Just for information: this is the standard template in the Custom Template Folder add-on.



          show_pagination_control();
          ?>
          csv_export_form( array( ‘export_fields’ => array( ‘first_name’,’last_name’,’email’ ) ) ) ?>

        2. The template you found in wp-content/plugins/pdb-custom-templates2 was placed there by someone, this file is not normally found in that directory.

          The edit you need to make to the pdb-list-edit-link.php template is explained in the article. On line 42, you will see:

          if ($this->field->name() === 'edit_link') {

          You may need to change ‘edit_link’ to match the name of the field where you want the link to be placed. Also, of course, that field must be configured to appear in the list.

        3. Hi Roland,

          Thanks for your quick response. I changed only row 15:
          $link_field = first_name

          The Record Page shows now a hyperlink (First Name) to edit the records. So it works great. Thank you again for your support!

          Best regards

        4. Yes, thanks, I updated the template to make it easier to find the place to change it.

  10. hello Roland
    thank you to point my to this page in order to be able to update a record in the front-end.

    I believe I have followed all the steps :
    – my list page contains [pdb_list template=edit-link search=true] : it displays lines with a clickable ‘edit-link’ field
    – when I click on the “edit-link” field of one entry in the list, it goes to my page containing [pdp_record] with the pid of that record : http://my-domaine/my-edit-page?pid=HNY0N

    but the page doesn’t open the record. It only displays [pdp_record]

    what went wrong?
    thanks again
    Albert

    1. make sure the shortcode is correct…should be [pdb_record]

      1. oops…so obvious..! at the end of the day something …it does work fine. thanks

Leave a Reply to AK Cancel 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.

196 thoughts on “Adding an Edit Record Link to the Frontend List

  1. Hello Roland,
    I followed all steps carefuly and link appeared sucessfuly but my changes aren’t saving in the record.

    1. Hi happy to help, but I don’t have enough info to know where it went wrong. When you click the link, do you successfully go to the where you can edit the record? So, then when you edit the record and hit save, what happens? Do you see any messages? How do you know it didn’t change anything?

      1. any modification i did in the records dosn’t appear when i refresh after the change.
        i tried to check the change after update with other browser and i found the change.
        if you need further clarification please let me know.

        1. OK, if you see the new data when you open the page in a new browser, this means that the first browser is caching the page, so you don’t see the change in that browser.

          If you have a plugin installed on your website that changes the browser caching, you should look at that for the cause of the problem. Participants Database does not do anything to browser caching.

  2. Hello! I did all you said in these posts, but I could generate a page in order to edit a record…

    1. If you follow the directions exactly, it will work, so you may need to read the instructions more carefully to make sure you understand them.

  3. Hi Roland,

    Is it possible to add the edit link button to the frontend of a single record as well?

    Thanks

    1. It is very similar to the way the link is added to the list. You need to create a custom template so you can place your edit button. The two things you need to create the link is first instantiate the PDb_Template object then use the get_edit_link() method of the object to get the URL for your link.

      <?php
      $record = new PDb_Template( $this );
      $edit_url = $record->get_edit_link();
      ?>
      <a href="<?php echo $edit_url ?>" >EDIT RECORD</a>

      1. Hi Roland,

        I tried to use the Edit Record template along with the Field Group Tabs but the tabs aren’t working.

        What do you advise for that please?

        1. What is the full shortcode you are using?

        2. this one:

          [pdb_single template=edit-button tabs=true]

        3. OK, what you need to do is add the field groups tabs code to your custom template. It’s not complicated, take a look at this article: Using Field Group Tabs with a Custom Template

        4. You are a star!

          Just added the code: just after <div class="wrap wrap_class ?>”>

          and worked perfectly

          Many thanks for your great help

  4. This is a great plugin that has been working well for years on my site, but today I updated to Version 1.9.7.4 and found that the Edit link was no longer active. On investigation I realised that the pdb-list-default.php file is obsolete and is now pdb-list-edit-link.php, so downloaded and installed it in the templates folder of my theme. However the edit link is still not active. I have not made any other changes e.g. to Participants database settings. My theme is up to date and WP is at 5.7.2. Any thoughts?

    1. Your template is most likely in the incorrect location. First, the update must have deleted your template because it was in the plugins folder.

      You can place the template in the wp-content folder in a folder named “participants-database-templates”.

      wp-content/participants-database-templates/pdb-list-edit-link.php

  5. I added the edit_link to the short-code [pdb-list] and works fine. I get a list of all members. However if I click on the dash-icons I get localhostundefined. What goes wrong?

    1. Make sure you have the “Participant Record Page” configured in the Participants Database settings under the Record Form tab.

  6. Using the edit-record-link I get the record-edit page. I want to skip in this form the personal info fields except the photo-link and want to add a DELETE-button beside the SAVE-button.
    I am looking in the class-file PDb_Init.php but my changes have no effect.
    How can I reach my goals?

    1. I advise you against editing the plugin directly, there are ways to modify how things work without doing that. Take a look at the documentation on how to control which fields are shown in the [pdb_record] shortcode.

      For deleting a record, you may not be able to add a “delete” button as you describe, the plugin doesn’t normally give the user a way to delete a record. You can take a look at this article for some ideas on how to do that:

      Giving the User a Way to Delete Their Own Record

      1. I added a field, named Edit, with the edit_link. This field is shown in the pdb-list.
        But it is also shown in the record-edit form. The latter is not the intention. How can I prevent this?

        1. The edti_link field should be a “placeholder” field, that will prevent it from showing up in the record-edit form.

  7. Two questions.

    1. I am able to display the Edit Link for each PDB record, however when I click on the edit link, it takes me to an empty page that says “No record was found”. I have [pdb_record] on the page and the POST ID added to the Record Form Settings > Participant Record Page”.

    When I click on the link from the list page, the target page shows up with the following URL.
    .example.com/edit-record/?pid=92IC2

    2. On the list page, how do I ensure that only records matching an index field (say userid=1234) are displayed? I want to limit the scope of record list (or display) to the WP users who created them.

    Appreciate your help.

    1. So, if the link is going to the page with the [pdb_record] shortcode, and the URL is properly constructed (looks like it is) then for some reason, the PID is invalid. Are you using the Participant Login plugin with the “One Time Use Private ID” setting? That setting may be incompatible with presenting a list of edit links on the frontend. Also, make sure there is no page caching active on any page with Participants Database shortcodes.

      Second question is aswered in my provious email to you. If you are using the plugin with WP users, don’t try to use the Participant Login add-on as well, they don’t work well together.

  8. Hi Roland
    i follow step by step and new list works perfectly, however if i try to search using default Search short code [pdb_search] it does not search or display requester data

    1. To show the search, use the “search” attribute of the list shortcode like this:

      [pdb_list search=true]

      You don’t need to use the pdb_search shortcode.

  9. Hello Roland,

    I could not download the Custom Template Folder add-on. Anyway, I did add your complete template (pdb-list-edit-link.php) in this location:
    /wp-content/participants-database-templates/

    Edit link page
    [pdb_list template=edit-link]

    Participants record page
    [pdb_record]
    Participants record page shows table of [pdb_record] with no records.
    Edit link page shows table of [pdb_list template=edit-link] with data but without edit link (hyperlink) or edit possibilities.
    I get the same view if I use [pdb_list template=edit-link] and [pdb_record] at the same Participants record page.

    Can you tell me what I have to do?
    Thanks in advance!

    1. What exactly was the problem in downloading the Template Folder plugin?

      If you don’t use the Template Folder plugin, you must place your custom templates in your theme. This is explained here: Using Participants Database Custom Templates. If you put your templates into the plugin folder, they will be deleted when you update thw plugin.

      It sounds like the [pdb_list template=edit-link] shortcode is not using the custom template. Make sure the template is in the correct location. Also, you must edit the template to match the field name you want to use for your link.

      1. Dear Roland,

        Thank you very much for your quick response and support. I don’t know why I couldn’t download the Custom Template Folder add-on yesterday. But today it works fine. After installation I saw two new folders: wp-content/participants-database-templates (this folder was empty) & wp-content/plugins/pdb-custom-templates2 (this folder contains a folder “templates” with a file named “pdb-list-edit-link.php”.
        I copied that file and moved it to wp-content/participants-database-templates.
        After that I added the shortcode of [pdb_list template=edit-link] to the Participant Record Page.
        The Participant Record Page shows now, like in the case of Bostjan Zrimsek (post of June 6 2020), a list of the records but without a link. And I see also an “Export CSV..” and file name for exporting all records of the database.
        If I edit the template text and use the text in your article, then I get a list of records without a hyperlink.
        You wrote that I have to edit the template to match the field name I want to use for my link. Where exactly do I have to change that?

        Thanks in advance!

        1. Just for information: this is the standard template in the Custom Template Folder add-on.



          show_pagination_control();
          ?>
          csv_export_form( array( ‘export_fields’ => array( ‘first_name’,’last_name’,’email’ ) ) ) ?>

        2. The template you found in wp-content/plugins/pdb-custom-templates2 was placed there by someone, this file is not normally found in that directory.

          The edit you need to make to the pdb-list-edit-link.php template is explained in the article. On line 42, you will see:

          if ($this->field->name() === 'edit_link') {

          You may need to change ‘edit_link’ to match the name of the field where you want the link to be placed. Also, of course, that field must be configured to appear in the list.

        3. Hi Roland,

          Thanks for your quick response. I changed only row 15:
          $link_field = first_name

          The Record Page shows now a hyperlink (First Name) to edit the records. So it works great. Thank you again for your support!

          Best regards

        4. Yes, thanks, I updated the template to make it easier to find the place to change it.

  10. hello Roland
    thank you to point my to this page in order to be able to update a record in the front-end.

    I believe I have followed all the steps :
    – my list page contains [pdb_list template=edit-link search=true] : it displays lines with a clickable ‘edit-link’ field
    – when I click on the “edit-link” field of one entry in the list, it goes to my page containing [pdp_record] with the pid of that record : http://my-domaine/my-edit-page?pid=HNY0N

    but the page doesn’t open the record. It only displays [pdp_record]

    what went wrong?
    thanks again
    Albert

    1. make sure the shortcode is correct…should be [pdb_record]

      1. oops…so obvious..! at the end of the day something …it does work fine. thanks

Leave a Reply to AK Cancel 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.