I'm new on using toolset. I found it amazing and I have taken some courses and reading documentation.
I'm constructing a site where I would do the following:
-In a cred form user introduces 3 fields ( 2 text and one date ).
-Compare theses fields with all the existing values of the existing custom post fields in order to see if exists a custom post type item with the combination of this 3 values.
-If it exists I would like to send the user to buy a product, and want that in the order was registered the data of the custom post field that we compared before.
-If not exists, give a error message, and continue on the same form. But not show any data to the user.
Is this possible to do? What was the approach to do this.
I'm trying to do it trough add a view filter on a cred form but it only compares the first field. IS this the correct aproach? Is possible to do through the filter editor? Is possible to do this with shortcodes or I have to use the filer api?
I would mainly like know the general technical way to do this.
Thanks in advance.
Joan
Dear Joan,
It needs some custom PHP codes, I suggest you try with CRED filter hook cred_form_validate, for example:
1) Create a CRED form for creating custom post
After visitors submit this form, choose the product post you needed
2) Setup custom PHP codes with filter hook cred_form_validate, like this:
When user submit above CRED form, use filter hook cred_form_validate to trigger a PHP function, in this PHP function get the value of three custom fields:
https://developer.wordpress.org/reference/functions/get_post_meta/
Use them to query the existed posts:
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
If there is any result, do nothing, if there isn't any result, then return an error, more help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
This hook provides custom validation for form fields
Thanks for your help.
Code is a little difficult for me. Maybe first I would like to know if is there a alternative way to do it. I explain you my project and maybe you know how to do it in a easer way.
Its a website where users can register and pay for one subscription and after they have paid the subscription they can pay for some activities. I would use 3 custom post types: User profile (CPT 1 associated to a USER) - that can pay the subscription for more than one - Subscriber ( CPT2: child of CPT1). Then every user can pay for Activities ( CPT3:child of CPT1 ) for every Subscriber (CPT2) that had paid the subscription.
I would like to register on the website the Subscribers that the subscription have been paid, and give the option to edit the data of every subscriber. Then I would like to register the activities that every user can pay and register the payments and the subscriber that has to do the activity.
In some cases the registration of the payment will be done through the back-end manually, not only through the purchase of a product on the website front-end.
I would like to validate if a subscription has been paid when a user want to purchase one activity for a certain subscriber.
I hope it was understandable.
Thanks in advance.
joan
I assume we are talking about this:
Only after user have a post in post type "Subscriber" ( CPT2), then the users can create new post in post type "Activities"
Here are my suggestion:
1) User profile (CPT 1 ) it is not necessary, you can setup custom user fields to store the user's information:
https://toolset.com/documentation/user-guides/user-fields/
2) You can setup "Activities" as child post type of "Subscriber",
https://toolset.com/documentation/user-guides/creating-post-type-relationships/
3) create a view to list "Subscriber" posts of current user:
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/
4) If there is a result, then display a CRED form for creating child "Activities" post,
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/
If there isn't any result, then display a link ask the user to buy your product.
Thanks,
Related to:
"4) If there is a result, then display a CRED form for creating child "Activities" post,
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/
If there isn't any result, then display a link ask the user to buy your product."
how can I do this if? how can I make that the toolset know if there is a result or not and show the CRED form for create activities or display a link ask the user to buy your product?
Thanks in advance
In view's loop section there are two built-in shortcodes:
[wpv-items-found]... [/wpv-items-found]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-items-found
Meta HTML wrapped in [wpv-items-found][/wpv-items-found] will be output if there are any posts | taxonomies | users returned by the View.
[wpv-no-items-found]... [/wpv-no-items-found]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-no-items-found
Content wrapped with [wpv-no-items-found][/wpv-no-items-found] will be output if there are no posts, taxonomies or users returned by the View.