I'm looking to have a frontend CRED form where I'd like the user to submit a review for a company that has completed a job for them. I'd like to have the user establish a single custom taxonomy item via a text field to be registered under the taxonomy "Company", however it doesn't seem the current "add_new" field doesn't support the standard text field. Is there a way to get this work within the context of the CRED form?
My attempts have involved the following variations:
[cred_field field='company_add_new' taxonomy='company' display='textfield' placeholder='COMPANY THAT SERVED YOUR NEEDS' class='form-control']
This first example doesn't even display the field.
and
[cred_generic_field field='company_add_new' taxonomy='company' type='textfield' placeholder='COMPANY THAT SERVED YOUR NEEDS' class='form-control' urlparam='']
{
"required":0,
"validate_format":0,
"default":""
}
[/cred_generic_field]
This example displays the field, but does not apply the taxonomy to the post or to the custom post type's Company taxonomy.
The page in question is hidden link
Any help would be greatly appreciated, thanks.
Well, CRED ShortCodes for taxonomies depend on what you set for the taxonomy:
Is it flat or hierarchical?
CRED generates this Code for each of the Taxonomy types:
(I use Product Categories as hierarchical and Flats as flat taxonomies)
<div class="form-group">
<label>Product Categories</label>
[cred_field field='product-category' display='checkbox' output='bootstrap']
[cred_field field='product-category_add_new' taxonomy='product-category' type='add_new']
</div>
<div class="form-group">
<label>Flats</label>
[cred_field field='flat' class='form-control' output='bootstrap']
[cred_field field='flat_popular' taxonomy='flat' type='show_popular']
</div>
As you see natively the syntax is not the same for both and both do not support the same attributes.
You can read more about them here:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
Now, for the Add New feature, depending on which type, natively you can choose from existing Hierarchical Taxonomies or add new ones by typing into a text field and clicking add.
In hierarchical Taxonomies you can also pick a parent term.
In flat terms you show popular terms (if there are some already) or add new ones similarly to the above explained.
Also here you type in a Text Box.
Can you let me know how that text box you try to create would differ from the one you already have, unless the placeholder?
This attribute is not supported in this case.
Well, I had the taxonomy set as hierarchical, which I believe is default anyway. I wanted it to be sorted and selected from the post edit page similarly to categories.
If the taxonomy is set to flat, the "add new" fields display an "Add" button along with the text field, which allows the user to list multiple taxonomy terms. I'm guessing these terms do not get submitted unless the "Add" button is selected, so hiding this button is likely not an option (if I'm wrong, please correct me here).
The thing is, this is not what I'm looking for in the form. I need to restrict the user to only a single taxonomy term listing, and they can't know that they're creating one. The user only needs to know that the text field they're filling out is identifying what company served them for the job that was done for them. Therefore once they click the form's Submit button, the field's value is submitted and added as a taxonomy term which can be pulled into a feed via a view.
Just looking to see if this is possible. If not, I can have the client assign the post to the correct "Company" taxonomy term when they approve it. I was hoping to get around having to do that, however.
Either you let the User add/create Terms with the CRED GUI, which you understand correctly, or you use Custom PHP in a cred_save_data() hook where you get the Text Field's value, and create a Term when the form is submitted.
This is possible following these steps:
1. Create a Text Field with Types (Single Line for example)
2. Include this in the CRED Form
3. The user types some value there
4. Apply a cred_save_data() hook to the Form:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
5. In this action get the Text Field's Value either with get_post_meta() or from the CRED Form's $_POST:
https://developer.wordpress.org/reference/functions/get_post_meta/
hidden link
6. Update your Taxonomy with the value you receive. Create a Term in the taxonomy with it. Use wp_insert_term() to insert the term:
https://codex.wordpress.org/Function_Reference/wp_insert_term
Toolset in this case either helps you with a stylable GUI in the Front End, or, you can use the cred_save_data() hook as above shown to fire your Custom Application in the right moment.
Thank you for your assistance. The information you have provided has helped greatly.