I have a student-donor many to many relationship. In donor template, I added a view to display all the linked students. Now, I need a way to:
1. add an existing student linked to the current donor in frontend
2. delete an existing student linked to the current donor in frontend
I tried the solution to this support ticket but I got issues with the short code and I don't have an idea what it's supposed to look like in the front end.
https://toolset.com/forums/topic/front-end-editing-of-post-relationships/
I don't have a similar example.
Here's the link to the donor template: hidden link
Thank you.
Hi,
Welcome to Toolset support. Please follow the steps mentioned in the documentation below:
https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/
1) Create a form to connect an existing Student to the current Donor
- Go to Toolset → Forms → Add New and choose Relationship Form.
- Pick your many-to-many relationship (e.g. student-donor).
- In the Form will setting, choose Create new relationship (connect items).
- In Which items will this form connect, set:
.The side that represents Donor to Current post (so the Donor is pre-selected from the template you place this form on).
.The side that represents Student to Let the user choose an existing item (autocomplete list).
- Save the form.
- On the Donor template (where a single Donor is displayed), insert the form and lock the Donor by passing the current post ID.
- Use the shortcode attributes that match your relationship’s sides (parent/child names depend on how the relationship was defined).
- For example, if Donor is the parent side and Student is the child side:
[cred-relationship-form form='connect-student-to-donor' parent_item='[wpv-post-id]']
- If your sides are reversed (Student is “parent”, Donor is “child”), swap the attributes accordingly:
[cred-relationship-form form='connect-student-to-donor' child_item='[wpv-post-id]']
2) Create a form to disconnect a Student from the current Donor
- Add another Relationship Form for the same relationship.
- In Form will, choose Disconnect related items.
- Save.
You’ll typically render this inside the View that lists related Students on a Donor page, so each row has its own “Remove” button.
Inside the View loop of Students (where the loop item is the Student and the current page is the Donor), insert the form and pass both item IDs. Example when Donor is the parent side and Student is the child side:
[cred-relationship-form
form='disconnect-student-from-donor'
parent_item='[wpv-post-id item="$current_page"]'
child_item='[wpv-post-id]']
Thanks.
Hi,
Regarding
2) Create a form to disconnect a Student from the current Donor
- In Form will, choose Disconnect related items.
When I create a new Relationship Form, there's no option for Disconnecting related items. I'm using Toolset Forms 2.6.23.
Please clarify how add a Remove link inside the View loop of Students.
Thank you.
My issue is now resolved after removing a duplicate many-to-many relationship. This shortcode now works.
[cred-delete-relationship role_items='$fromViews' relationship='student-donor' redirect='self']Remove[/cred-delete-relationship]
Thank you!