Skip Navigation

[Resolved] How can I set up a CRED form to edit a post that does not exist yet?

This thread is resolved. Here is a description of the problem and solution.

Problem: I understand that a CRED form can be used to create posts. I understand that a different CRED form can be used to edit a post. Can you explain how to set up a CRED form to edit a post that does not exist yet?

Also, how can I restrict the number of posts a User can create with CRED?

Solution: CRED forms are not restricted to a particular post, so you can reuse the same CRED form for any post in a particular post type.

To limit the number of posts a User can create with CRED, you can use a View. Let's say you have a custom page with a CRED form that allows your Users to create an Ad. That Ad's author will be the current User, once it's created. You need to determine whether or not to display the CRED form, based on how many Ads have been created by the current User. You can filter a View by post author, and you can react differently based on the number of results.

Set up a View that shows all posts where the author is equal to the current User. A View's Loop Output contains two sections - results found and no results found. You can use these two sections to display different information based on whether or not there is already a post by the current User. Or, you can use other conditional code that tests the number of results found.

Relevant Documentation:
https://toolset.com/documentation/user-guides/creating-cred-forms/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

This support ticket is created 7 years, 1 month 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by collinC-2 7 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#591217

Hello, I am trying to set up a feature where a logged in user with the Member user types can edit a custom post type entry similar to the example here: https://toolset.com/documentation/user-guides/cred-training-course/part-5-building-forms-content-editing/. I've also got a members section set up similar to this tutorial (https://toolset.com/documentation/user-guides/cred-training-course/part-7-building-account-page-login-form/) so the Member can log in.

The Member can only submit one Ad and can only edit the Ad that they have submitted. I think I've got Access set up so that the Member can only edit the Ads custom post type and I've created a page that is only readable by the Member user type where the CRED form will live. I'm also using the Bainternet Posts Creation Limits plugin to limit them to one entry of that custom post type.

I have two questions. First, I can see where you can set the CRED form to edit specific pages or posts. However, if the user submits a new custom post type entry, how do you set up the CRED form to edit an entry that hasn't been created yet?

Second, is there a way to use WP Types to natively restrict the number of custom post type entries a user type is allowed to add/edit without using another plugin?

Please let me know if I can provide any more information on my issue.

Thanks,

Collin Condray
Director of Technology
BlueZooCreative.com

#591351

However, if the user submits a new custom post type entry, how do you set up the CRED form to edit an entry that hasn't been created yet?
A CRED form edits posts in general, it's not restricted to a specific post by design. You can reuse a single CRED form for all posts of that same post type. If you want to limit the scope of this CRED form to only a specific post ID, then that needs to be accomplished indirectly by only showing the form under certain circumstances (e.g. the current page ID is 1234, etc.). You can use Views or Conditional HTML to test those circumstances and show or not show the form based on those circumstances.

Second, is there a way to use WP Types to natively restrict the number of custom post type entries a user type is allowed to add/edit without using another plugin?
Indirectly, you can accomplish this using a View. Let's say you have a custom page with a CRED form that allows your Users to create an Ad. That Ad's author will be the current User, once it's created. You need to determine whether or not to display the CRED form, based on how many Ads have been created by the current User. You can filter a View by post author, and you can react differently based on the number of results.

Set up a View that shows all posts where the author is equal to the current User. A View's Loop Output contains two sections - results found and no results found. You can use these two sections to display different information based on whether or not there is already a post by the current User. Place that View on the page instead of the CRED form. Place the CRED form in the no results found section, and some other message in the results found section (outside the loop).

For a more direct approach, you can use the cred_form_validate hook to perform any PHP validation you want when a CRED form is submitted. Click the orange "More" button for examples:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#591789

Christian,

These responses made sense. I was able to address both of my questions based on your answer. Thanks for you help on this!

Collin Condray
Director of Technology at BlueZooCreative.com