Dear Sir/Madam,
I submitted a question from the new ticket system https://toolset.com/forums/topic/cannot-update-the-parent-relationship-using-relationship-form/ I follow the suggestion and face another problem that I cannot solve. I want to have further question about the ticket but it was closed.
I have the District (1) to Estate (many) relationships. I created the Relationship Form and inserted into a Layout "Estate Relationship Layout"
[cred-relationship-form-container]
<div class="form-group">
<label>Estates</label>
[cred-relationship-role role='child']
</div>
<div class="form-group">
<label>Districts</label>
[cred-relationship-role role='parent']
</div>
[cred-form-feedback field='feedback' name='feedback']
[cred-form-submit field='submit' name='submit']
[/cred-relationship-form-container]
I create Views to list out all the Estates and insert the relationship form link to loop editor
<wpv-loop>
<div class="row">
<div class="col-sm-3">[wpv-post-title]</div>
<div class="col-sm-9">[cred-relationship-form-link form='estate-relationship-form' child_item='$current' layout_slug='estate-relationship-layout']Connect another District[/cred-relationship-form-link]</div>
</div>
</wpv-loop>
When I click the relationship form link, it redirects me to the relationship form
From the front-end form, if the estate has been associated with a district, it prompts No district can be associated to ....
If the estate has not yet associated, it only allows me to select or enter from very little options of the districts post, I can't see all districts from the selection. I can see all districts from selection if I update the estate post from the dashboard.
How can I associate district if estate not yet associated with any district or change the district if the estate has already associated with one district?
You will not use Relationship Forms to connect One To Many Posts, you usually use that only for Many To Many Relationships.
I suggest not using Relationships Forms at all if not really required. They have no API and no notifications, so you cannot use them at full extent.
If possible, use Post Forms, where you can easily connect a Child to a Parent.
(the many to the one end).
I am not sure what you mean by "I have the District (1) to Estate (many) relationships. I created the Relationship Form and inserted into a Layout "Estate Relationship Layout""
Did you copy the code of the form to a layout? That will not work.
If you autogenerated the Form and inserted the Form to a Layout, it will work, but as said, it's not required for One To Many Relationships, in fact, it will hinder the forms full potential.
Now - since you already use it like this and also inserted the Link in the View, the reason that you can not select any other post if something is already associated. I mean, it's a One To Many Relationship you use, so you can not add many parents...
>The issue that you can select only a few posts, if not associated yet, might be due to the Field in the Form, did you eventually choose to display only posts of a certain author (the current user)?
Do you want to allow a link in a View of Estates, so to link that particular Estate in the Loop to a particular parent, or any parent?
Dear Beda,
Many thanks for your reply.
Do you mean the Relationship Form can only be applied to the post-relationship is many-to-many?
"I have the District (1) to Estate (many) relationships" mean I have the posts District and Estate with relationship 1-to-many, one District has many Estate
If the Relationship Forms do not support 1-to-many, how can I create the relationship between the District and Estate when I create a new Estate from Front-end form? Could you show me the api code that I can create and update the relationship?
Best regards,
Kelvin.
No, I did not say they do not support it.
I wrote it should not be used if not needed explicitly because Relationship Forms have no API and no notifications.
So, if you later want to have additional code hooked to that form or notifications sent, that won't be possible.
Since you use a non-Many to Many Relationship (where Relationship Forms are the ONLY method to connect those in the front end), I suggest not using Relationship forms for the above-mentioned reasons.
Now, if you want to proceed using it, that is no issue - but you cannot add notifications and neither Custom code, nor do they have proper redirection management, as you surely noticed and that cannot be customized, since the API is missing for.
Related to "Could you show me the api code that I can create and update the relationship?", what do you mean?
We have this API if you programmatically want to get or connect posts:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
However, that is irrelated to the ticket's topic.
Is the initial issue still up to date? If so, can you elaborate which forms you'd prefer to use (Relationships Forms without notification or API) or Post Forms with that possibility? I also activate a private reply to show me the issue live if you require, and it still persists.
Dear Beda,
Sorry for my wrong interpretation. I will study the API link you provided.
It is fine if no notification and additional code hooked, I only need to allow user to create and update the relationship after creating the Estate ( child ), the user should only need to select which District ( parent ).
Please advise what I should do to use the Relationship Forms
Best regards,
Kelvin.
The API does not require any attention unless you plan to use it. You will not need it, if you use Toolset Forms to connect posts generally.
Since you only need to allow the user to create and update the relationship after creating the Estate ( child ) post, the very, absolutely easiest is letting them do that when they create the New Estate (Child) post.
In fact, if you create a "Create New Post" form, which lets you add Estates, then you can also insert the field where the user can choose an existing "parent" post.
That's really the simplest, most lean approach you can take.
Now, if you instead want the user to create MANY Estates or also connect estates of other users, and all that starting from a list of Estates, then you'd have to choose a slightly different approach where you simply would add a link to the Edit Post Form of those posts.
In that form you can then as well add a parent post picker, allowing the users to connect a parent.
Do you need an example of this? I can set such a form for you in the site as example, if you allow this and can share access details.
That website returns an ERR_NAME_NOT_RESOLVED over here.
I am in Vietnam, if this is an issue here my IP to whitelist it:
42.112.158.146, Ho Chi Minh City, SG VN
Dear Beda,
Sorry for my typo mistake to the private message, I updated it, please try again.
Best regards,
Kelvin.
This is a Post Form to create new Estates where you can choose a District when adding the Estate:
hidden link
It can be inserted anywhere, post or page or layout. It will create new estates, connected to the one district chosen
This instead is an edit form, doing the same:
hidden link
That form can be inserted either in single estate posts, or in a Content Template.
If you insert it to a Content Template, later you can use that to have a "Edit Estate" link on the front end, leading to the Edit Form, where you can edit the parent as well.
Note, however, in your case as you use Layouts, you cannot use a Content Template but need to insert the form to a Layout:
hidden link
If you build a View, listing all existing estates, you can add the same "Edit" Link in the View loop, so that on the front end, a list of links to edit the estates and connect a parent becomes visible:
hidden link
Please let me know if you need more help on this.