Tell us what you are trying to do?
I would like to build a front-end CRED form that allows the user to select from existing items in an already created Many-To-Many relationship. If possible, all on one page, but I am unable to figure out how to do so.
More Detail
I'm building a quoting program. For simplicity sake I have a quotes post type and products post type in a many-to-many relationship already set up. Everything works great in the backend and I can do exactly what I need to there...
BUT I actually want to use a frontend CRED form whereby a person can build a quote and select from the existing products to assign to that quote. On one page.
I can't seem to find a way or any doc on how to do this. Essentially, in the backend, when I go to my quotes post type, once I set the relationship, a UI loads at the bottom of the screen that allows me to use the Quotes Products relationship, where I can choose to Add new Product or Connect existing Product. (I also have set an intermediary Quantity field so they can choose how many of the product will show) and it opens in a lightbox and proceeds.
How can I accomplish this on CRED on a frontend form? Or is it not possible?
Is there any documentation that you are following?
I'm sorry but it is not possible to use a single form to both publish posts and connect other posts to it (the exception being specifying a parent on a form to publish child posts).
Connecting posts from a many-to-many relationship or the many side of a one-to-many relationship is done with separate relationship forms.
You could do this in a single form if you are comfortable writing PHP.
There would be two parts to this.
The first is that you would add a generic field (e.g. a select field) to your form to display a dropdown of the products that could be connected, and you would populate the dropdown options using a custom shortcode that returned a JSON object of the products to choose from.
Then you would use the cred_save_data hook to process the form submission, and use the relationships API to connect the relevant posts (and then update the intermediate post with a custom field value which would also need to be available as a generic field in the form).
We can't write that for you, but if you want to go down that route and need a few pointers let us know.
Hi Nigel - understood. That seemed to be the case from all my tests before I bugged you guys! Until the post is saved, it doesn't have an ID and thus doesn't have a way to associate with the new one. I don't get how it works in the backend but I will leave that to WordPress magic.
So my next ask, if these are on seperate pages, I can arrange it in a flow like Step 1: Have them make the page. Step 2: Associate Step 3: Go to the view. Is there a way to seamlessly transition from the create page to the associate relationship page?
For example I'm used to the term "passing a variable" like as a URL parameter or such, but I'm not sure how to go about that. And when I search that on the forums I'm getting seemingly unrelated results so maybe its not the right term.
For example, I saw how to make the Relationship form and set that up. But when you create a new post and navigate to the relationship page you have to select the post again. I'd like to have that automatically populated with the post that was just created.
And further more, is there a way to associate more than one post at once?
This is the most advanced thing I've attempted to make so sorry if some of these questions are somewhat amateurish. Thank you for the assistance.