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.

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

  1. Added the edit_link field but I am confused on where to add:
    “Set the Display Column to a number indicating which column you want the edit link field to appear in.”

    1. Pls disregard, I figured it out.

      1. Yes, but I appreciate you letting me know the tutorial has outdated info in it.

  2. Is there anyway to get a search bar for this page to get a specific record instead of having to search through the paginated pages to find the record?

    1. You can enable a search control for the list in the shortcode by using the “search” attribute like this: [pdb_list search=true]

      Details in the documentation: user searching & sorting the list

  3. Hi, I also tried to implement the plugin to provide and edit link page where I can change the record details, in that page I have the [pdb_record] shortcode,
    but the page I go to doesn’t have pid=number, shouldn’t it be auto-generated
    It looks like this,
    http://mysite/homepage/index.php/edit-link/?pid=

    after …/?pid= is blank. How can I make it private link. I don’t really use private link from email.

    1. if I go to the above link, the shortcode shows me “No record was found.”

      1. Got resolved by re-install the plugin, thanks

    2. If there is no code for the pid value, then I would suspect there is a problem in the custom template that is preventing the private ID value from getting placed in the link. Check the custom template, make sure it is correct.

  4. All is working but the edit link shows up as this (from browser source):
    my_url.com/edit-voter-record/?pid=I3542
    How do I get it to show as:
    EDIT
    Thanks.

    1. You need to set the “default” value of your placeholder field.

      1. I did … so I kept playing and it turns out that the form element field was “text” not “link.” Works now. BUT the search dropdown includes “Edit Link,” the title of that field. How do I eliminate? (Also, is there a way to get an email when you respond?)
        Thanks.

        1. Craig,

          Well, I don’t know what you did, but I’d say check the manage database fields page to make sure the field titles are all correct.

          Normally, when you start a topic here, you will get an email when there is a response, there is a preference to “subscribe” to the topic, maybe you unchecked that.

        2. Fixed it and have it running. Thank you.

      2. Hi Roland,
        After the last plugin update, the “edit_link” field only shows the code with the record ID (link works but not nice on the website). I tried to add a value as you recommended in the “default value” field as well as in the “Attibute” but it does not change anything. Do you have any tip?
        Thanks in advance

        1. Are you using a “placeholder” field to show the edit link? I can’t see the problem here so I don’t know what is going wrong.

        2. Hi, I’m not sure what you mean by placeholder. in the Database, I have a field “edit_link”, (text type), I added value “Edit” for the attributes help, default value and attributes. I have a Modify page with the following code [pdb_single] [pdb_record]
          if you want I can share screenshots my email carine.kowalski[at]gmail.com
          thanks a lot for your help!

        3. For this purpose, you should use a “placeholder” type field, not a text field. You need to put the clickable text into the “default” configuration for the field.

        4. Hi Roland, Thank you SO MUCH!!! it worked! all good :-)

  5. I’m hoping you would be willing to help me sort out how to use this to set the edit_link address to a button on the page. Using a few templates I’ve created a page that displays info in multiple sections based on your article about multiple databases and several other examples you’ve shared and am now hoping to provide the users an update option via a button to match my “renew membership” button on the page.

    I’m very new to web development, php, etc. so any specific guidance you could provide would be greatly appreciated!!

    Sharing the code in the template and the custom php plug-in I’m using makes this post too long so please let me know if you’d like to see anything specific.

    Thank you!!
    Ted

    1. Ted, I’m sorry, I can’t really offer that kind of general debugging support…if you want to ask about a specific problem you’re having, I’m happy to answer your questions if I can.

      1. Thanks for the response Roland. My specific question is truly how to use the content of the edit_link address as my address in the button I’d like to use to send people to the “edit your info” page (aka the page with [pdb_record] short code on it.

        1. OK, it’s important to understand that you can only provide such a link in a context where you know who the user is and can therefore know which record to send them to. Usually, such a link is provided after someone fills out a form and then that link is emailed to them. The links in this tutorial are not for a specific record, but for all records, so it doesn’t need to know who the user is.

          Can you tell me more about what you are trying to accomplish?

        2. Ted, send me an email with your question, posting code in the comments doesn’t work too well, thanks. support@xnau.com

        3. My prior replies about what I’m trying to accomplish have been deleted. Was there an issue with the content of my responses?

          Generally speaking, I’ve used your prior posts about capturing the logged in WP user’s identity and used that to match a field in the DB and filter content down to the logged in user.

          Now I’m just trying to figure out how to assign this edit link field to an Edit button as I am using a custom template to assign very specific parts of the data to various cells of a table so it does not work to simply display the field as a series of fields together like this example demonstrates.

          I’m a rookie at this stuff so I am likely overlooking something simple but would greatly appreciate any guidance you can offer. Thank you!

        4. Ted, your posts were garbled and not helpful to others–not your fault, it’s just not a good venue for that kind of discussion. I’m happy to provide support via email if you need to send code examples.

          This plugin does require some technical knowledge if you want to use it to do things outside of the normal setup. I can help you with specific things, but your question here is too general for me to simply answer.

          In the template provided in the tutorial, the method for determining whether to apply the edit link is on line 42. You may need to change the logic here so that your link can be assigned in a more flexible way, but I don’t understand what you’re trying to accomplish, so I can’t be more specific than that, I’m sorry.

          It may also be that you need to use a different template altogether to get a different layout…this example provides you with the basic functionality that can be applied to any template.

          If you can set up the display the way you want it to look, then share a link to that, it may be a better starting point for helping you.

        5. I figured as much. I tried to provide my email to take the conversation offline. I’m hoping submitting my followup to you on this via your contact us form will suffice in getting an email message to you; I just submitted this. If that did not work, please let me know. Thank you!

  6. Is there any way of adding an edit button to the single record page? I’ve successfully added it to the list view, however, for ease of access i’d like it in the single record page. Has anyone created a complete template for this? I have no idea what i’m doing.
    Thanks in advanced!

  7. Hi! I am probably doing something really stupid, but I followed this tutorial and all I’m getting is a column with the word “Edit” in it on my front end list, but it is not clickable. I have the template file under the proper directory, everything under settings is set up, I have the list page, records page and single page all set and specified in settings. I can send you my WordPress admin login if you are able to help! :)

    1. Hi Brittany,

      The first thing is to make sure the list shortcode is using your custom template. One way to do that is to add a title or something to the template so that it will be visibly obvious the custom template is in use. If you have debugging on, you can also see the template path in the HTML source. If you’re not getting your template, things to check are: the name of the template file, that it is correctly called in the shortcode, and that it is in the right place. If you are using a child theme, the “templates” folder must be in the child theme folder.

      Make sure you have the list columns you want shown configured on the Manage List Columns page, if that is all set up, but only one column is showing, you have a code issue with the template. If you are changing the template provided in the tutorial, make sure your changes are not breaking the template.

      I’m sorry, I cannot log in to your site to check.

  8. I had the frontend edit link working. But it seemed like when the new update came in yesterday, the link disappeared. I noticed that the ‘pdb-list-edit-link.php’ file was gone from the templates folder… so I recreated it. But the edit link is still missing. I checked, the shortcode is still requesting to use that template. What else should I check?

    Thanks for this great plugin! BTW… I’m totally not using this for people… I’m using it to track the progress of a game. :-)

    1. I’m sorry you lost your work! Custom templates need to be placed outside of the plugin folder in order to survive an update. Take a look at this article for instructions on where to put your template files: Using Participants Database Custom Templates

      Once you have that set up and it still does not work, post here with what you’re seeing and I’ll try to get you running again.

  9. Preciso da ajuda de vcs, mesmo seguindo o tutorial de edição bem detalhadamente não consigo mostrar na página que tem o shortcode [pdb_record], a lista de registro, apresenta a mensagem: nenhum registro encontrado, como posso resolver este problema, para que apresente toda lista como é apresentada com o [pdb_list]???????Por favor me ajudem…..

    1. I’m sorry, I can’t answer in Spanish… this tutorial is only for the “list” [pdb_list] shortcode. I doesn’t work for the [pdb_record] shortcode.

      In the plugin settings, under the “Record Form Settings” tab, make sure that the “Participant Record Page” is set up.

      1. Mr. Roland,

        A opção página de registro do participante não aparece na Configuração do formulário de registro, aparece na configuração para gravar formulário, e já realizei a configuração apontando a página que tem o shortcode [pdb_record], e não funciona, preciso saber se falta alguma configuração????
        Thanks.

        1. The settings for the Single Record Page and Single Record Link Field are under the “List Display Settings” tab.

  10. I solved that problem! – it was to do with the difference between newly added and previously imported records. I’d left the old “username” field in the imported records to guide me as I added and filled the “user_login” fields. I’d set it as required initially and then taken it off the signup page when I got the system to recognise the current user, but I noticed it was still appearing in the edit record page, marked as required.

    So although the plugin was allowing me to add new records without the old “username”, any attempt to update those records failed unless I filled it in.

    Stupid really but maybe a submission warning on the edit record page about required fields, like you get when adding a new record, would have alerted me to it earlier.

    Thanks for helping me eliminate other issues!

    1. Glad to hear it turned out. These kinds of problems can be pretty tricky to diagnose.

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

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

  1. Added the edit_link field but I am confused on where to add:
    “Set the Display Column to a number indicating which column you want the edit link field to appear in.”

    1. Pls disregard, I figured it out.

      1. Yes, but I appreciate you letting me know the tutorial has outdated info in it.

  2. Is there anyway to get a search bar for this page to get a specific record instead of having to search through the paginated pages to find the record?

    1. You can enable a search control for the list in the shortcode by using the “search” attribute like this: [pdb_list search=true]

      Details in the documentation: user searching & sorting the list

  3. Hi, I also tried to implement the plugin to provide and edit link page where I can change the record details, in that page I have the [pdb_record] shortcode,
    but the page I go to doesn’t have pid=number, shouldn’t it be auto-generated
    It looks like this,
    http://mysite/homepage/index.php/edit-link/?pid=

    after …/?pid= is blank. How can I make it private link. I don’t really use private link from email.

    1. if I go to the above link, the shortcode shows me “No record was found.”

      1. Got resolved by re-install the plugin, thanks

    2. If there is no code for the pid value, then I would suspect there is a problem in the custom template that is preventing the private ID value from getting placed in the link. Check the custom template, make sure it is correct.

  4. All is working but the edit link shows up as this (from browser source):
    my_url.com/edit-voter-record/?pid=I3542
    How do I get it to show as:
    EDIT
    Thanks.

    1. You need to set the “default” value of your placeholder field.

      1. I did … so I kept playing and it turns out that the form element field was “text” not “link.” Works now. BUT the search dropdown includes “Edit Link,” the title of that field. How do I eliminate? (Also, is there a way to get an email when you respond?)
        Thanks.

        1. Craig,

          Well, I don’t know what you did, but I’d say check the manage database fields page to make sure the field titles are all correct.

          Normally, when you start a topic here, you will get an email when there is a response, there is a preference to “subscribe” to the topic, maybe you unchecked that.

        2. Fixed it and have it running. Thank you.

      2. Hi Roland,
        After the last plugin update, the “edit_link” field only shows the code with the record ID (link works but not nice on the website). I tried to add a value as you recommended in the “default value” field as well as in the “Attibute” but it does not change anything. Do you have any tip?
        Thanks in advance

        1. Are you using a “placeholder” field to show the edit link? I can’t see the problem here so I don’t know what is going wrong.

        2. Hi, I’m not sure what you mean by placeholder. in the Database, I have a field “edit_link”, (text type), I added value “Edit” for the attributes help, default value and attributes. I have a Modify page with the following code [pdb_single] [pdb_record]
          if you want I can share screenshots my email carine.kowalski[at]gmail.com
          thanks a lot for your help!

        3. For this purpose, you should use a “placeholder” type field, not a text field. You need to put the clickable text into the “default” configuration for the field.

        4. Hi Roland, Thank you SO MUCH!!! it worked! all good :-)

  5. I’m hoping you would be willing to help me sort out how to use this to set the edit_link address to a button on the page. Using a few templates I’ve created a page that displays info in multiple sections based on your article about multiple databases and several other examples you’ve shared and am now hoping to provide the users an update option via a button to match my “renew membership” button on the page.

    I’m very new to web development, php, etc. so any specific guidance you could provide would be greatly appreciated!!

    Sharing the code in the template and the custom php plug-in I’m using makes this post too long so please let me know if you’d like to see anything specific.

    Thank you!!
    Ted

    1. Ted, I’m sorry, I can’t really offer that kind of general debugging support…if you want to ask about a specific problem you’re having, I’m happy to answer your questions if I can.

      1. Thanks for the response Roland. My specific question is truly how to use the content of the edit_link address as my address in the button I’d like to use to send people to the “edit your info” page (aka the page with [pdb_record] short code on it.

        1. OK, it’s important to understand that you can only provide such a link in a context where you know who the user is and can therefore know which record to send them to. Usually, such a link is provided after someone fills out a form and then that link is emailed to them. The links in this tutorial are not for a specific record, but for all records, so it doesn’t need to know who the user is.

          Can you tell me more about what you are trying to accomplish?

        2. Ted, send me an email with your question, posting code in the comments doesn’t work too well, thanks. support@xnau.com

        3. My prior replies about what I’m trying to accomplish have been deleted. Was there an issue with the content of my responses?

          Generally speaking, I’ve used your prior posts about capturing the logged in WP user’s identity and used that to match a field in the DB and filter content down to the logged in user.

          Now I’m just trying to figure out how to assign this edit link field to an Edit button as I am using a custom template to assign very specific parts of the data to various cells of a table so it does not work to simply display the field as a series of fields together like this example demonstrates.

          I’m a rookie at this stuff so I am likely overlooking something simple but would greatly appreciate any guidance you can offer. Thank you!

        4. Ted, your posts were garbled and not helpful to others–not your fault, it’s just not a good venue for that kind of discussion. I’m happy to provide support via email if you need to send code examples.

          This plugin does require some technical knowledge if you want to use it to do things outside of the normal setup. I can help you with specific things, but your question here is too general for me to simply answer.

          In the template provided in the tutorial, the method for determining whether to apply the edit link is on line 42. You may need to change the logic here so that your link can be assigned in a more flexible way, but I don’t understand what you’re trying to accomplish, so I can’t be more specific than that, I’m sorry.

          It may also be that you need to use a different template altogether to get a different layout…this example provides you with the basic functionality that can be applied to any template.

          If you can set up the display the way you want it to look, then share a link to that, it may be a better starting point for helping you.

        5. I figured as much. I tried to provide my email to take the conversation offline. I’m hoping submitting my followup to you on this via your contact us form will suffice in getting an email message to you; I just submitted this. If that did not work, please let me know. Thank you!

  6. Is there any way of adding an edit button to the single record page? I’ve successfully added it to the list view, however, for ease of access i’d like it in the single record page. Has anyone created a complete template for this? I have no idea what i’m doing.
    Thanks in advanced!

  7. Hi! I am probably doing something really stupid, but I followed this tutorial and all I’m getting is a column with the word “Edit” in it on my front end list, but it is not clickable. I have the template file under the proper directory, everything under settings is set up, I have the list page, records page and single page all set and specified in settings. I can send you my WordPress admin login if you are able to help! :)

    1. Hi Brittany,

      The first thing is to make sure the list shortcode is using your custom template. One way to do that is to add a title or something to the template so that it will be visibly obvious the custom template is in use. If you have debugging on, you can also see the template path in the HTML source. If you’re not getting your template, things to check are: the name of the template file, that it is correctly called in the shortcode, and that it is in the right place. If you are using a child theme, the “templates” folder must be in the child theme folder.

      Make sure you have the list columns you want shown configured on the Manage List Columns page, if that is all set up, but only one column is showing, you have a code issue with the template. If you are changing the template provided in the tutorial, make sure your changes are not breaking the template.

      I’m sorry, I cannot log in to your site to check.

  8. I had the frontend edit link working. But it seemed like when the new update came in yesterday, the link disappeared. I noticed that the ‘pdb-list-edit-link.php’ file was gone from the templates folder… so I recreated it. But the edit link is still missing. I checked, the shortcode is still requesting to use that template. What else should I check?

    Thanks for this great plugin! BTW… I’m totally not using this for people… I’m using it to track the progress of a game. :-)

    1. I’m sorry you lost your work! Custom templates need to be placed outside of the plugin folder in order to survive an update. Take a look at this article for instructions on where to put your template files: Using Participants Database Custom Templates

      Once you have that set up and it still does not work, post here with what you’re seeing and I’ll try to get you running again.

  9. Preciso da ajuda de vcs, mesmo seguindo o tutorial de edição bem detalhadamente não consigo mostrar na página que tem o shortcode [pdb_record], a lista de registro, apresenta a mensagem: nenhum registro encontrado, como posso resolver este problema, para que apresente toda lista como é apresentada com o [pdb_list]???????Por favor me ajudem…..

    1. I’m sorry, I can’t answer in Spanish… this tutorial is only for the “list” [pdb_list] shortcode. I doesn’t work for the [pdb_record] shortcode.

      In the plugin settings, under the “Record Form Settings” tab, make sure that the “Participant Record Page” is set up.

      1. Mr. Roland,

        A opção página de registro do participante não aparece na Configuração do formulário de registro, aparece na configuração para gravar formulário, e já realizei a configuração apontando a página que tem o shortcode [pdb_record], e não funciona, preciso saber se falta alguma configuração????
        Thanks.

        1. The settings for the Single Record Page and Single Record Link Field are under the “List Display Settings” tab.

  10. I solved that problem! – it was to do with the difference between newly added and previously imported records. I’d left the old “username” field in the imported records to guide me as I added and filled the “user_login” fields. I’d set it as required initially and then taken it off the signup page when I got the system to recognise the current user, but I noticed it was still appearing in the edit record page, marked as required.

    So although the plugin was allowing me to add new records without the old “username”, any attempt to update those records failed unless I filled it in.

    Stupid really but maybe a submission warning on the edit record page about required fields, like you get when adding a new record, would have alerted me to it earlier.

    Thanks for helping me eliminate other issues!

    1. Glad to hear it turned out. These kinds of problems can be pretty tricky to diagnose.

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