I want to pre-fill a relationship field in a Toolset form using the url parameter in a View filter result.
I have a View search where users input a specific value, hit search, and the View result is displayed on a different page. From this Views search result page the users can fill out a form.
I need the relationship field default to be automatically populated by the result of the View. This may be possible with a URL parameter, but I would need the post ID from the result in that parameter, and I haven't found that as an option in Views.
Another option was somehow programmatically populating the default value of the relationship field using PHP, however, I can't see a way to insert PHP in the Toolset form.
What do you suggest?
-------------------------------
What is the link to your site? hidden link
The specific value you can input to test this search and see what I am trying to do is: 1234
Okay you have a search View that produces some result on another page. Then from that result, you want to link to a Form that includes a post relationship field, which should be automatically populated by the ID of the result from the previous page.
- What type of post relationship are we talking about, is this a one-to-many or a many-to-many relationship?
- Have you already set up a Content Template to hold the Form?
- Is the child form link approach not applicable for your case? Why not? https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/
The relationship is one-to-many.
The reason the child form link doesn't work in this instance is a) we don't want users to have to input the same information twice, and b) we don't want users to be able to search other parent content, or accidentally attach the child form to another parent item that they don't own.
Maybe there is a better way to set this up? It would be fine if the user had to click on the parent item so they could fill out a child form, but I haven't figured out a way to make it work, even following the documentation you provided. It looks like the child form link requires the child content be created before the link can happen, right?
It would be better if the flow could work like this:
Search for vehicle (parent item) -> select vehicle and go to vehicle page -> fill out child form on that page like a complex comment form.
Am I making this too complicated, or is there a way to make that work?
The reason the child form link doesn't work in this instance is a) we don't want users to have to input the same information twice, and b) we don't want users to be able to search other parent content, or accidentally attach the child form to another parent item that they don't own.
Okay I think the child form link is still the best way to go here. You can actually hide the parent input field in the Form so the User isn't aware of it, and it will still be set to save the appropriate parent. Basically you will edit the Form code and add some CSS to hide the parent select field and its container element. I can help with that if you'd like. The User won't have to select the parent post again, it will be preselected automatically based on a URL parameter (see below),
It looks like the child form link requires the child content be created before the link can happen, right?
No, in this case the parent post is created first. The child post link can be displayed somewhere on the parent post template or in a View of parent posts. The link redirects the User to a Form to create a new child post. In the link URL there will be a URL parameter that specifies the parent post (this is generated automatically when you insert the child post link). That URL parameter automatically sets the correct parent post in the Form. This field can be hidden from the User with a bit of CSS.
It looks like the child form link requires the child content be created before the link can happen, right?
I should add that many-to-many relationships work like you are describing here. But since yours will be a one-to-many relationship, child post creation happens at the same time as the parent post link is established.
My issue is resolved now. Thank you!
I was trying to add a Relationship Link form to the View, instead of just a Relationship Form. When I got the right form added it worked as expected. Thank you! This is working really well.