Startseite › Toolset Professional Support › [Gelöst] Hide or Disable CRED Form after submit
Problem:
How can I check if a Post in a Views Loop has Children?
Solution:
You can use the Types API for this.
A great Custom ShortCode example is documented here:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/ > Displaying Many-to-Many Relationship Using Types PHP API
Look for the code "Below, there is an example on how to create a shortCode that returns all children posts IDs, which is useful to check if a post has child posts, inside a Views Loop."
Also in the above DOC, it's elaborated how you use this in a HTML conditional.
Here is a more detailed version, which also checks for the Current Logged in user is the author of that Child Post or not:
https://toolset.com/forums/topic/hide-or-disable-cred-form-after-submit/#post-391185
Relevant documentation:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/
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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
Verwandte Dokumentation:
Dieses Thema enthält 7 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von mirjanaM vor 8 Jahre, 4 Monate.
Assistiert von: Beda.
Hi,
i have a post form with CRED (see here https://toolset.com/forums/topic/register-for-event/), so when user will register for an event they must Click to register.
The Problem what i have. Whe the user comes back to this form he see that form again.
How can i do that, that the form will be disable after submit.
The Form is used in every post so the user can register for every event...but after he register that must be disable for that even or shown a massage (better) that he has registered for that.
[credform class='cred-form cred-keep-original'] [cred_generic_field field='post_title' type='hidden' class='' urlparam=''] { "required":0, "validate_format":0, "persist":1, "generic_type":"post_title", "default":"[wpv-post-title id="$testprodukt"]" } [/cred_generic_field] <div class="tp_regist_field"> <label class="cred-label">Als Produkttester registrieren:</label> [cred_generic_field field='regist' type='select' class='' urlparam=''] { "required":1, "validate_format":1, "persist":1, "default":["1"], "options":[ {"value":"1","label":"Ja"}, {"value":"2","label":"nein"} ] } [/cred_generic_field] </div> <div class="hidden"> <div class="cred-field cred-field-anzeigename"> <label class="cred-label">Anzeigename:</label> [cred_field field='anzeigename' post='registrierung' value='[wpv-user field='nickname']' urlparam=''] </div> <div class="cred-field cred-field-vorname"> <label class="cred-label">Vorname:</label> [cred_field field='vorname' post='registrierung' value='[wpv-user field='user_firstname']' urlparam=''] </div> <div class="cred-field cred-field-name"> <label class="cred-label">Nachname:</label> [cred_field field='name' post='registrierung' value='[wpv-user field='user_lastname']' urlparam=''] </div> <div class="cred-field cred-field-email-adresse"> <label class="cred-label">Email:</label> [cred_field field='email-adresse' post='registrierung' value='[wpv-user field='user_email']' urlparam=''] </div> <div class="cred-group cred-group-parents"> <div class="cred-field cred-field-_wpcf_belongs_testprodukt_id"> <label class="cred-label"> testprodukt Parent </label> [cred_field field='_wpcf_belongs_testprodukt_id' value=''] </div> </div> </div> <div class="tp_submit">[cred_field field='form_submit' value='Registrieren' urlparam='']</div> [cred_field field='form_messages' value=''] [/credform]
Hope someone can help.
Thanks Mira
It can't be done without a Custom Check.
You are creating a Child Post to the current Event.
That child post is "registration" and is authored by "current logged in user"
So, as example you can use a HTML conditional to show the CRED Form or button to register only if the Current Logged in user has NO such child Post with parent "Current Event"
Since you can NOT check child posts with a Toolset ShortCode, you need a Custom ShortCode that queries all Child posts and filters the ones out that are authored by "current user" and "current parent post"
A example how to achieve this is here:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/ > Displaying Many-to-Many Relationship Using Types PHP API
Look for the code "Below, there is an example on how to create a shortCode that returns all children posts IDs, which is useful to check if a post has child posts, inside a Views Loop."
This can be extended to check for children with a given author and a given parent (which is stored in the Types field _wpcf_belongs_parent-post-type-slug_id)
It is custom code though, but since it uses Toolset API I can assist and guide you if you have issues with the API.
I can though not code this for you or provide a ready to go application logic, as this is a not native feature of Toolset.
Thank you
Hi Beda,
thank you for helping me again. As you see on this post https://toolset.com/forums/topic/register-for-event/ you helpt me to make the relationship and connection (hope u remember 😉 ). All is fine. But how i told the problem is...that the user can register more then one time. Thats not good.
So i must prevent this somehow.
I think u mean this code from your link
[wpv-conditional if="( '[has-child-posts]' eq '0' )"] You display things if does NOT have child posts [/wpv-conditional] [wpv-conditional if="( '[has-child-posts]' eq '1' )"] You display things if DOES have child posts [/wpv-conditional]
But i dont understand how i can do that. Hope you can help.
Mira
Yes, sure I recall 🙂
You identified the correct Custom ShortCode.
In the DOC it's elaborated how to create and use it.
For your reference:
Below, there is an example on how to create a ShortCode that returns all children posts IDs, which is useful to check if a post has child posts, inside a Views Loop.
This is the function you will put into your Child Theme functions.php
function child_posts_exist_func( $atts ){ $child_posts = types_child_posts('child-post-type-slug'); if ($child_posts) { return 1; } else { return 0; } } add_shortcode( 'has-child-posts', 'child_posts_exist_func' );
After you register the ShortCode in Toolset > Settings > Front-End content > 3rd party ShortCode arguments
Then, you use it in a View like below:
[wpv-conditional if="( '[has-child-posts]' eq '0' )"] You display things if does NOT have child posts Your CRED Form or Button [/wpv-conditional] [wpv-conditional if="( '[has-child-posts]' eq '1' )"] You display things if DOES have child posts Your message [/wpv-conditional]
Now, above function ONLY checks if there are Children.
It does NOT check if the child is by the logged in user.
Fort this you would evolve the function and add a check in the post query (get_posts) for the author:
https://codex.wordpress.org/Template_Tags/get_posts
Of course you will first need, in that function, to also get the current logged in user.
https://codex.wordpress.org/wp_get_current_user
Let me know if you need more help with the Toolset related part of this code,
Thanks
Is there nothing like....that will work out of the box.
If custom Field has value > 1 then ...
Like this
[wpv-conditional if="( $(featured) eq '1' )"] This post is featured. [/wpv-conditional]
my php is very bad...thats why i mainly use Toolset 😉
I mean the first part with the shortcode is not a problem while u guid me in the right way....but the second part is a pice of luck and trying.
Toolset does not provide a ShortCode to check if a Child Post exists on a Parent Post.
You can use my above suggestion.
Please acknowledge that advanced applications also require advanced Code and Logics.
If you need custom programming work which is beyond the scope of our support, I would suggest you consider contacting one of our certified partners from this link:
https://toolset.com/consultant/
You will get the custom assistance you need to get on with your project.
I am happy to assist the development of above suggested code using the Toolset API.
Unfortunately Toolset does not cover all edge cases of WebSite Applications, always you will find things where you need specific tweaks.
For this we provide our API, which lets you create powerful applications on top of the native GUI features of Toolset.
You have one other chance, which might work for you.
1. Create a View and list your Child Post type
2. Set a Query filter in there, as the below:
Select posts that are a children of the current post in the loop.
and
Select posts with the author the same as the current logged in user.
3. In this View insert NOTHING to the Loop but ABOVE the loop just AFTER the [wpv-items-found] ShortCode use something like this condition:
[wpv-conditional if="( '[wpv-found-count]' eq '0' )"]you can add your CRED here[/wpv-conditional]
(We check if there are child posts, if so, do not display the form, if not, display it)
4. In your View where you actually want to Display the CRED Form ( Button ) or not, you will query the Parent Post Type, and inserts above View to the Loop.
This will produce your CRED form ONLY if there are Posts child to the current parent AND authored by the logged in user.
Let me know if that suites you.
Hi Beda,
first i tryd your last solution. From point 4 it wont work anymore.
The i try to get it to work with your first solution.
But the code from me must be wron so it still displays the Cred form after sending....so i hope u can help a little bit more.
here the code form my functions.php...
function child_posts_exist_func( $atts ){ $child_posts = types_child_posts('registrierung'); if ($child_posts) { $current_user = wp_get_current_user(); $author_name = get_post_meta($post->ID, 'author_name', true); global $post; $args = array( 'author' => $author_id, 'post_type' => 'registrierung', ); return 1; } else { return 0; } } add_shortcode( 'has-child-posts', 'child_posts_exist_func' );
Now it work´s....Thank you.