Skip Navigation

[Resolved] Select and register results of a filtered view threw a CRED form

This support ticket is created 6 years, 9 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Author
Posts
#549665

Hello,

I'm new with posts' relationships in CRED forms so I'm not quite sure about this...

CPT1 is "Products"
A product may be supplied by one or several suppliers.
Product has a "Product Type" taxonomy.

CPT2 is "Suppliers"
A supplier may supply one or several products.

CPT3 is "Offers"
An offer is the price for one product by one supplier
In order to allow this many-to-many relationship, "Offers" is a children CPT of both "Products" CPT and "Suppliers" CPT.
For instance, I may have :
- supplier1's offer for product1 is 10$ ;
- supplier2's offer for product1 is 20$ ;
- supplier1's offer for product2 is 30$ ;
- supplier2's offer for product2 is 40$.

That structure also allows a same supplier to make various offers for the same product ; for instance :
- supplier1's offer for product1 is 10$ in winter ;
- supplier1's offer for product1 is 50$ in summer.

CPT4 is "Price Requests"
A request is a selection of the best available offers for one product.
Most requests will include several offers, and some offers will be included into several requests.
In order to allow this new many-to-many relationship, I must create CPT5, "Best Prices", which is a children CPT of both "Price Requests" CPT and "Offers" CPT.

Now, I need to be able to create a new "Price Request" (CPT4) threw a CRED form including :
1- Checkboxes : Products types (CPT1 taxonomy) I want to look into ;
2- Select : Product (CPT1) I want to look for offers ;
3- Multiselect : Suppliers (CPT2) from which I want offers ;
4- Checkboxes : Offers (CPT3) I want to set as "Best Prices" (CPT5).

So first question is : is the structure all right ? Couldn't it be simplier and/or more efficient in order to achieve what I want ?

And then, if the structure is OK, I have at least two major problems :
A- How to use a view as a checkbox into a CRED form ?
B- How to create several children posts of my main post threw the CRED form ?

Thank you very much for your kind help.

#549702

Dear Roman,

I think the structure is OK, since your request is complicate, so there isn't simple workaround.
Q1) How to use a view as a checkbox into a CRED form ?
You can output your own checkbox field in CRED form with CRED shortcode [cred_generic_field], see our document:
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

Use views result as options of the [cred_generic_field] shortcode, see similar thread:
https://toolset.com/forums/topic/upgrade-to-views-1-11-broke-a-cred-cred_generic_field-select-populated-by-a-view/

Then you will need to save the result into database:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Q2) How to create several children posts of my main post threw the CRED form ?
One CRED form can only create/edit one post, it is not possible to created multiple child posts with single CRED form, so you will need to follow our document to setup the CRED form for creating child post:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

#549723

Thank you.

Q1) If it is possible I'd rather not use the cred api : it is precisely to avoid PHP I'm using Toolset plugins... On another CRED, I have this field

[cred_field field='_wpcf_belongs_produit_id' value='' order='title' ordering='asc' required='true' select_text='--- Select fournisseur ---' validate_text='produit must be selected' class='form-control' output='bootstrap']

that uses "belongs" and shows a list of posts of the parent CPT into a select. What I would need is to replace this select field by a checkbox field.

Q2) The child posts "Offers" (CPT3) must be shown into the parent CRED form. So if I must create one CRED form for each post creation, that would mean the page should load both the main CRED form (to create the "Price Request", CPT4) AND 1 CRED form for each "Best Price" (CPT5) selected.

But I search a bit around and found those two threads :

https://toolset.com/forums/topic/create-multiple-posts-with-a-single-cred-form-2/
On this one, it seems Nigel has the exact solution I need, but the thread stops there...

https://toolset.com/forums/topic/multiple-edit-post-cred-forms-on-same-page/
On this one, russelL seems to have a similar issue. Here is an idea ; I'm wondering would it work ?
- Have a giant CRED form that edits my "Price Request" (CPT4) ;
- Into this form, insert a view with filters and a loop that loads each one of "Available Prices" (CPT3) within a single field CRED form ;
- When validating this single field CRED form, it creates a new post in "Best Prices" (CPT5), which is child both of "Price Request" (the giant CRED form edits this post), and of the "Available Price" (the post used to create the relationship to the "Price Request").

The idea is very simple but I wonder if it's achievable.

Thank you.

#549746

Q1) There are some misunderstands,
a) the shortcode [cred_field field='_wpcf_belongs_produit_id' ...], works only for creating child post, but in your case, it is for creating parent "Price Request" (CPT4) post,
b) and one child "Best Prices" (CPT5) post can have only one parent "Price Request" (CPT4) post,
so it is not possible to replace this select field by a checkbox field.

Q2) It is not recommended to put CRED form insider Views loop, it will conduct some unexpected result, I suggest you put a CRED form insider a individual page, display a CRED form link in the view's loop. please check our document to setup it:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

#551543

Please don't close this thread yet.
Thank you.

#551871

OK, I setup the thread status as "Waiting for user feedback", please update this thread when you need more assistance.

#552158

Maybe I missed something from the beginning and my whole structure may be the problem then.

I have several products supplied by several suppliers.
Each supplier has set his own price on his products.
I need the supplies manager to make a research on one specific product, and shortlist the suppliers for the project manager.
Then the project manager receives an alert with the shortlist, and choose the final supplier among those.

I thought in setting this up threw CRED forms and email notifications, but maybe there is an easier way ?

Thank you.

#552334

Here is my suggestion:
1) CPT5, "Best Prices" is not needed, since there is only one "Best Prices" for each "Price Requests" post.
I suggest you try these:
1) Create four custom post types: "Products", "Suppliers", "Offers", "Price Requests"
a) "Offers" is the child post type of "Products" and "Suppliers"
b) "Price Requests" is the child post type of "Products" and "Offers"

2) supplies manager can create a "Price Requests" post, setup the parent "Products" post, then he will be able to see a list of related "Offers" posts
https://toolset.com/documentation/toolset-training-course/part-9-many-to-many-relationships-in-toolset/
Then supplies manager can edit the "Price Requests" post, choose the parent "Offers" post, which is the best option in his mind.

#552699

That indeed seems the simpliest way...

But I still need the shortlist (which is a selection of prices, which I call "best prices"). Maybe woocommerce could do this ? That way the Cart would be the "best prices"... ?

#552835

I don't think Woocommerce can do this, here need some custom codes, here is my suggestion:
1) supplies manager can create a "Price Requests" post,
2) after the manager submit the CRED form, redirect him to a page, and pass URL parameter "Products ID" and "Price Requests ID" to the target page A,
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

3) in this target page A create a view list related offer posts (display price field value) according to the URL parameter "Products ID",
4) user choose one of the offer post, redirect him to another page, pass URL parameter with and "Price Requests ID" and "offer ID" to the target page B,
5) In the target page B setup a CRED form for editing "Price Requests" post, edit the specific "Price Requests" post according to the URL parameter "Price Requests ID", setup it's parent "offer" post according to URL parameter "offer ID"

In both CRED forms: step 2) and step 5) you can use CRED commerce and Email notification as what you want:
https://toolset.com/documentation/user-guides/using-cred-commerce-to-add-payments-to-forms/
https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/

#553160

Thank you very much for your help, which have been very useful.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.