Skip Navigation

[Resolved] Unable to create button that allows users to edit a post

This support ticket is created 4 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by Nigel 4 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1481659
Capture.PNG

I am trying to:

Create a button that allows users to edit a post.

For older forms, using the following code in a content template seems to work:

<button>
[cred_link_form form='3111' form_name='Edit Booth Post' text='Edit %TITLE%' target='_self']
</button>

However, this does not seem to work for newer forms. For the edit form with the ID 30522 I tried to do:
<button>
[cred_link_form form='30522' form_name='Edit Booth Post' text='Edit %TITLE%' target='_self']
</button>

But this resulted in a non-functional button.

Then, I tried following the following documentation: https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-editing/

1. I created a content template and didn't assign it any content.
2. I added the form to the template, resulting in the template containing the following code:
[cred_form form='edit-booth-new-test']
3. I posted the link to the content template within the content template of the post type that I would like to edit. The result was a button with the following code:

<button>
[toolset-edit-post-link content_template_slug='edit-booth' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]
</button>

Link to a page where the issue can be seen: hidden link

**Please note that to see the button you must be a user of type` canyonemployer`

I expected to see: A button that links to the new edit form

Instead, I got: A button that is not functional

#1482697

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2020-01-28 at 11.39.06.png

Hi Michael

For testing I moved the toolset-edit-post-link shortcode outside of the conditional shortcodes you have in the template, and I then found that the link worked as expected.

The problem isn't with your edit form link, it is with your conditional shortcodes.

I didn't create a user to test those, but you have nested conditions, first that the current user needs to be the post author, then that the current user role is canyonemployer. Only then would the form link be visible.

You may not need both, or either, of these, as you have Access installed and you can use that to define permissions for the edit form (and the link won't be displayed if the user doesn't have permission).

Seems like you would want to allow canyonemployer's to edit their own posts with that form, but not edit others' posts.

#1483007

Hi Nigel,

Thank you for your help. I think I didn't explain well what I am trying to do. I am trying to display certain edit button forms for certain users, rather than setting up access privileges for them. Ideally, I would like for each user to edit their page is to have an edit button display on the post that they created.

However, my challenge is that different user types have different post forms for creating the same post type, which means that each user type requires a different edit button. I would like to avoid having several different types of edit buttons display to the users as that would probably confuse them, but ideally I would like each user to be able to view an edit button on their post that corresponds to the edit form of the post form that they used.

I thought that the easiest way to do this would be to have a different edit button with a link to the corresponding edit form display depending on the type of user.

The standard form has a custom type called "Job Types" with the following options:
FULL-TIME
PART-TIME
INTERNSHIP/CO-OP
REMOTE

When a user posts with this form, I would like for them to see these options on the edit form. However, there are other forms with different options for "Job Types", such as:
FULL-TIME
PART-TIME
ON-CALL
SHORT-HOUR
TEMPORARY

This means that if a canyonemployer goes to their post, they will see an edit button that links to a post form that is the same as they one they used to create the post. But if a user who used a different post form goes to their post, they will see a different button that will link to that post form. Ther reason is that if a user, let's say of type canyonemployer who posted with that form goes to edit their page, I don't want them to see the options from the standard form, (i.e FULL-TIME, PART-TIME, INTERNSHIP/CO-OP, REMOTE), I would like for them to see the options for their form.

What is strange is that, for some reason, even if the nested conditional logic, it does work with the old toolset edit forms that were created a while go (IDs 21791 and 3111), but does not seem to work with the new ones that are created. Is this expected nested conditions? Perhaps a solution would be to have multiple separate conditional blocks? Is there a solution that you would recommend?

Thank you again for your help.

#1484403

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

"Ideally, I would like for each user to edit their page is to have an edit button display on the post that they created."

Different forms for different types of users.

When you say different types of users, do you mean these users have different roles? Otherwise, what distinguishes the types of users and the form that they should see?

If users have different roles and the edit form they should use is determined by their role then it still sounds like Access permissions is the way to go.

You can add five different edit links to five different forms.

You set the permissions for the forms for the role (or roles) in question such that the users can only edit their own posts and not posts authored by other users.

In that case the edit links only show up if you are viewing your own post, not when viewing someone else's.

And if you were viewing your own post, you wouldn't see all 5 links, because your role would only be given permission to use one of those 5 forms.

This all depends on the question above, about what distinguishes users and the kind of form the users should see. If it is roles, try using Access permissions.

#1485007
Form link without a button.PNG
Empty button if form link not displayed.PNG

Hi Nigel,

Thank you for your help. It does sound like Access is the answer--I think I misunderstood what it is able to do.

Yes, I did mean that there are users with different roles that I would like to use slightly different forms. I did some testing and I did not realize that when Access is able to hide the link when a user role is not given permission to use the form. I thought that the link would still show and only when the user tries to use the form, their access would be denied. This would have been a problem because several edit buttons would be visible to each user role, but it seems like Access is able to hide the link to the form based on permissions.

This means itt seems like I am able put several different edit forms in the content template like this:

(edit form 1)
[toolset-edit-post-link content_template_slug='edit-booth' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]

(edit form 2)
[toolset-edit-post-link content_template_slug='edit-booth2' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]

(edit form 3)
[toolset-edit-post-link content_template_slug='edit-booth3' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]

And as long as I set the proper permissions in access, only the edit form that is meant for a given user role will be visible to that user.

This seems to work well as long as I do not wrap the edit form link ( [toolset-edit-post-link content_template_slug='edit-booth' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]) within a button tag. If I do, and the user role is not allowed to use the form, the button will still show without a link.

Is there a way that I can still wrap this link within a button tag or style it in some way?

#1486619

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You have identified a flaw in the solution—wrapping the link in a button will leave useless buttons exposed where the link is not output—but the solution is just a matter of styling the link so that it looks like a button.

When you insert the edit link you can specify classes to add to the link (you can just add them with a class attribute if you edit the existing shortcodes) which will enable you to easily target these button-less links. You can then check the style rules for button elements and apply them to the class(es) you add to the links.