Skip Navigation

[Resolved] CRED Form Submitted Custom Taxonomy for Custom Post Type

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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)

This topic contains 4 replies, has 2 voices.

Last updated by zacharyL 6 years, 5 months ago.

Assisted by: Beda.

Author
Posts
#582872

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.

#582970

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.

#584968

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.

#585166

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.

#586095

Thank you for your assistance. The information you have provided has helped greatly.

The forum ‘Types Community Support’ is closed to new topics and replies.

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