Skip Navigation

[Resolved] CRED form failure when contains custom field and taxonomy with same slug

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

Problem:
A CRED form contains a custom taxonomy and custom field which both use the same slug, and the taxonomy does not display.

Solution:
The issue has been fixed and a patch is available in this erratum: https://toolset.com/errata/cred-form-does-not-show-taxonomy-field-when-form-contains-custom-field-and-taxonomy-with-same-slug/

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

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 9 replies, has 2 voices.

Last updated by Nigel 6 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#606150

I am trying to:
I have a hierarchal taxonomy associated with Listings post type.
See: hidden link

Link to a page where the issue can be seen:
I would like it to be able to be added to the form here (under Country - above contact email):
hidden link

I expected to see: checkboxes for all the categories

Instead, I got: nothing!

THanks!

#606285

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Stephanie

How did you add the field to your CRED form? Can you show me where you insert the field?

As a quick test, try auto-generating the form and seeing if it is output correctly, and compare how the field is inserted then with what you have done. (If you don't want to change your current form you can make a second form purely for testing where the markup is auto-generated.)

#607390

That's what I did when I first inserted it to see how it would appear.

Here is the test form (auto-generated):
hidden link

Maybe I've screwed up the taxonomy setting.

The code for the field 'locations' the cred form is here:
hidden link

The taxonomy set up on the back end is as per here:
1. hidden link
2. and here: hidden link

#607464

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Stephanie

I followed your link to the auto-generated form and I was confused for a while because it looked like it was working, but then I realised you have a checkbox custom field location and a checkbox taxonomy location, and the custom field is working correctly and the taxonomy not, yes?

I set up a test site locally to test the same scenario and I found it didn't work, much like in your case.

I'm going to escalate this as a bug, but in the meantime I suggest you try renaming the slug of your taxonomy, even a small change such as to "locations". Then edit your post form to change the field slugs for the taxonomy to match.

I did the same and that fixed it.

#607831

Renaming the slug worked - thanks - it now displays using:

[cred_field field='countryloc' display='select' single_select='true' value='' urlparam='' output='bootstrap' class='form-control wpt-form-select']

One more extension of this - is there a way to make this is a required field?

#607874

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Stephanie

There are no settings to make a taxonomy required.

You would have to add custom validation for that, using the cred_form_validate hook (https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate).

There is an example in that documentation.

Is that something you are able to have a go at implementing, or do you need more help?

#607883

Hi Nigel,

I've been going through the history - there are quite a few people that have modified functions.php to do this - I'm comfortable with php but want to make sure I'm modifying the correct functions.php file.

Is this the functions.php:
wp-content > plugins > cred-frontend-editor > application
or do you mean the theme functions?

Would the solution here work?
https://toolset.com/forums/topic/making-custom-taxonomies-in-a-cred-form-required/

Thanks.
Stephanie

#607887

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Stephanie

You would edit the theme's functions.php, never the plugin files, and you might find it easier to use a plugin such as Code Snippets to add your PHP, in which case were you to ever change theme your code would be preserved.

The first code in that thread you linked to is what you require, with suitable edits for the id of the cred form and the slug of the taxonomy.

#608142

OMG! Code Snippets <3
Thank you...

Hopefully this will be the last post.

Reference for the custom taxonomy?
see: hidden link for what I mean
I tried wpcf_countryloc and that didn't seem to work.

Inserting into views it is [wpv-post-taxonomy type="countryloc" format="name"]

How does that translate for custom taxonomies?

Thanks!

#608480

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Stephanie

I don't know without checking, so why don't I tell you how to check so that you can work this kind of thing out for yourself in the future if you have related questions.

To know what field name or slug is being used, dump $fields to your debug log so that you can see the fields submitted with the form and how to access them.

So once $field_data has been split into $fields and $errors you can use error_log( $fields ); to print it to the debug.log to inspect it.

To make complex variables ($fields is an array) more readable, use it like this:

error_log(print_r( $fields, true ));

If you haven't already, turn on the debug log by editing your wp-config.php file and change the line with WP_DEBUG like so:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

That will create a debug.log file in your wp-content directory which you can examine in any text editor.

If you can't get it to work, let me know and I'll check.