Skip Navigation

[Resolved] Category selection in CRED form

This support ticket is created 6 years, 8 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 9 replies, has 2 voices.

Last updated by Christian Cox 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#561632
Screen Shot 2017-08-20 at 09.42.24.png

I am developing a site in which visitors are able to submit book reviews from the front end of the site using a CRED form.

I have been able to set this up successfully and the book reviews are submitting.

However, I need to limit the options available to the visitor when they are submitting the form, specifically in the taxonomy terms they are able to select (this post uses a custom taxonomy "Reader Article Types").

Please take a look at the attached screenshot at this point.

As you will see, this allows visitors to select any taxonomy term - even ones which aren't for book reviews.

What I need to do is:
• Limit the terms that the visitor can select to "Book Reviews" and its immediate child terms ("Anthology" down to "Young Adult" in the attached screenshot)
• The user should not be able to select the other terms ("News for Writers" down to "Sate & Screen reviews > Stage" in the attached screenshot)

One additional question: Is it possible to display the post edit text area as a plain text box (i.e. remove the styling options on the front end, so the user can only submit standard paragraphs)?

I hope you can help me. With this tweak, everything would be working beautifully.

Very best wishes, and thanks again for you time.

Very best wishes,
Andrew.

#561740

Hi, I'll be glad to help.

However, I need to limit the...taxonomy terms they are able to select
I see what you mean. There is not a good way to limit the taxonomy terms available in a CRED form from the form editor in wp-admin, unfortunately, but there are a couple of options can recommend instead:
1. Use JavaScript to remove the undesired options so the User cannot select them. If you can show me the form on your live site, I may be able to suggest the JavaScript that will accomplish this for you. One potential problem with this approach is that you may see the undesired options briefly before they are removed from the page.

2. Hard-code the desired options in your CRED form and use the cred_save_data hook to apply the selected terms to the created post. This option is okay if you don't plan on adding or removing terms often, but can be cumbersome to keep up-to-date as options are modified. More info about this hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

3. Use a View to create a generic select field that includes an option for each term that is a child of the Book Reviews term. Use the cred_save_data hook to apply the selected term(s) to the created post. This option is the most reliable and the easiest to maintain, but it's more difficult to set up. I can help if you get stuck. More info about using a View to create generic field options:
https://toolset.com/forums/topic/how-use-a-shortcode-instead-of-options-for-cred-forms

Is it possible to display the post edit text area as a plain text box?
Not the standard post body editor, but there are other options. Are using CRED to create a standard WP Post or a Custom Post Type? If it's a Custom Post Type created in Types, you can disable the post content field and use a separate custom field instead. If it's the standard Post type, you could add a multiline custom field to Posts, or use the excerpt field instead, and remove the editor field from your CRED form.

If you want to put the content entered in a custom field into the post body, you can again use the cred_save_data hook. If you need additional assistance with this, please open a separate ticket so we can address that issue individually. This helps us keep the forum organized. Thanks!

#563112

Hi Christian,

Many thanks for getting back to me with such a thorough reply, and apologies for my delayed response.

Display of taxonomy terms in frontend CRED form
So a brief summary (to check I understand) of those three options would be:

  • Hide with Javascript: will prevent users from seeing terms, thought there may be momentary display until javascript loads. You can help to provide correct javascript. This seems a reasonable option, but would we always need to keep hiding new terms as they are added?
  • Hardcoding in the CRED form: use cred_save_data hook to apply selected terms to the post created. Cumbersome as does not automatically add new terms. Seems the least attractive option
  • Use a dynamic view: create a generic select field which allows selection of any term which is a child of the parent "Book Reviews" term. You're able to help me if I get stuck using the docs. This sounds like the most graceful solution, so I'd like to give this one a try. If I can sort it, then it's a skill I can use repeatedly in other places on the site.

Preferred solution: I'll go ahead with option 3, see if I can figure that out, and report back. Hopefully I'll manage it, but if not then your offer of help is very much appreciated, thank you.

Display the post edit text area as a plain text box
Sorry for not raising a separate ticket for this one originally, that would have been much more sensible. I'll go ahead and do that now as advised, as I do have some follow-up ????

Thanks again Christian, your help is awesome as ever!

Very best wishes,
Andrew.

#563212

Hide with Javascript
Your understanding of this is correct except for the last part. We will set this up to be dynamic, so any terms that are added or removed later will be updated in the term filter automatically.

Hardcoding in the CRED form
Your understanding seems accurate.

Use a dynamic view
Sounds like a plan! Let me know if you get stuck.

#563238

Hi Christian,

Wow, that javascript solution sounds fabulous. I'm intrigued by that one.

Can I check something on my preferred option (option 3: use a dynamic view) please?

I'm using php templates to build the site, rather than Views. If I go with option 3 and create a view, can I add that view to the php template file? Or would I not then be able to use a PHP file in this case to create the webpage?

Thanks again, and very best wishes,
Andrew.

#563310

You can use the Views API to output a View using PHP:

$args = array(
    'id' => '12345'
);
echo render_view( $args );

General PHP programmer references:
https://toolset.com/documentation/programmer-reference/

render_view reference:
https://toolset.com/documentation/programmer-reference/views-api/#render_view

Let me know how you would like to proceed.

#563355

Awesome! So I can go ahead with my preferred Option 3 to create the dynamic view, but still add the php into the relevant template file...and all will work well?

#563371

It should be okay to include a dynamic View by placing a shortcode inside the Loop Output of another View, which is rendered using PHP. Whether or not all will work well remains to be seen - it depends on too many variables for me to be able to say definitely yes or no. I say try it out on a small scale. If you run into issues, we can address each issue in a ticket.

#563376

Okay thanks.

I'll give this all a shot, where I can, and get back to you.

Very best wishes,
Andrew.

#563991

No problem. I have marked this ticket as pending an update from you. We can pick up again when you are ready. No need to reply at the moment, the ticket will stay active for 30 days.

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