I am trying to:
Allow a submitter to choose amongst category values (category A, category B, or category C) by using radio buttons or a drop down. Currently a submitter can enter any value in a free text format (see attached screenshot; it is named Categorie).
This is the code in the CRED form:
<div class="form-group">
<label>Categorie</label>
[cred_field field='adverts' class='form-control' output='bootstrap']
</div>
Link to a page where the issue can be seen:
hidden link
I expected to see:
The pre-defined category values I already defined as a taxonomy.
Instead, I got:
A free form entry field that allows submitters not to choose amongst the values that I defined, but instead submit any value.
Hi, the cred_field shortcode accepts different attributes that control the design style of the form element. Radio is not an option for a taxonomy field, but a single select field can be shown instead. Try this:
[cred_field field='adverts' display='select' single_select='true' class='form-control' output='bootstrap']
Hello Christian,
A drop-down, single select would be perfect. I applied the shortcode (see screenshot), unfortunately to no avail.
You need login credentials to have a look?
Kind regards,
Ruud
In the URL bar of the screenshot you provided, the form ID is 3531. On the site, I can inspect the markup and see the form ID is 3530. Is it possible you're editing a different CRED form in wp-admin?
But when I change the label Categorie to CategorieII in the concerning form, it is changed as I would expect, as you can witness here: hidden link
Moreover, I only made 3 forms so far; see attachment.
Kind regards,
Ruud
Okay I see, I was looking at the Layout ID in the screenshot. Sorry for the confusion. Yes, please provide login credentials here so I can take a look. Thanks!
Sorry but this login is not working for me. Can you check the credentials once more?
Wasn´t working for me either...sorry about that!
Okay I see, this is a flat taxonomy. The "display" setting only applies to hierarchical taxonomies, so it's not possible to change the style of this taxonomy field. I think you could accomplish something similar with a generic select field. If there are just a few options, you can set them manually using the generic field wizard.
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
Or if there are many terms, you can use a View to provide the select field options. The value of each option should match the term slug. This is a bit more complex, but another ticket discusses this approach in detail:
https://toolset.com/forums/topic/how-use-a-shortcode-instead-of-options-for-cred-forms
Instead of using the post ID in the loop, you would use the term slug.
Then use the CRED API to save the selected term when the form is submitted. Here's an example where the generic select field has the slug generic-select-term:
add_action('cred_save_data', 'set_term_from_generic_select',100,2);
function set_term_from_generic_select($post_id, $form_data) {
$forms = array( 12345 );
if( in_array( $form_data['id'], $forms) ){
$taxonomy = 'adverts';
$tag = $_POST['generic-select-term'];
wp_set_object_terms( $post_id, $tag, $taxonomy, true );
}
}
Replace 12345 with the numeric ID of this form. Let me know if you have questions about this approach and I can offer some assistance.
Thanks for the help and patience, Christian,
I abandoned the flat taxonomy and got it working.
Kind regards,
Ruud