Skip Navigation

[Resolved] At least one item must be selected from a taxonomy. If not an errormessage

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 6 replies, has 3 voices.

Last updated by Waqar 9 months, 2 weeks ago.

Assisted by: Waqar.

Author
Posts
#2682440

I used the customcode supplied by Toolset but it does not work. The name of the code is 'mandatorytaxonomy'.
If I activate the code the code does not work (no errormessage) and no records will be submitted in the Frontend User submission Form.
I tested it with taxonomy 'koopofhuur'.
The link to my site is? hidden link

#2682456

Nigel
Supporter

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

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

Hi there

Could you please give details of the custom code you are using?

What is the purpose of the code?

What is the context it should work in?

It sounds like you have a frontend form to register users. The code should be applied when submitting the form, yes?

#2682806

Hi Loek,

Thank you for sharing these details.

I see two points due to which the custom code will not work:

1. In the Toolset's custom code section, I see that this code snippet has been added under the name 'mandatorytaxonomy'.

But the defined function name (tssupp_require_category) and the one called in the filter (tssupp_require_sector) are different.
( screenshot: hidden link )

These function names should be the same, for example:


function tssupp_require_sector($field_data, $form_data) {
.....
add_filter( 'cred_form_validate', 'tssupp_require_sector', 10, 2 );

2. This code snippet is not active. Once the function names have been fixed, please activate this code snippet and then test the form again.
( screenshot: hidden link )

This should help and let me know how it goes.

regards,
Waqar

#2683021

Hi Waqar,

I changed the code and the code snippet is activated but it still does not work.
Tx for your reply.

Regards
Loek

#2683209

I did some troubleshooting and changed the following line in the code snippet:


if ( empty( $fields['koopofhuur']['value'] ) ) {

To:


if ( empty( $fields['koopofhuur']['value'][0] ) ) {

Here is the updated code and I've tested it to be working now:


// Put the code of your snippet below this comment.
function tssupp_require_sector($field_data, $form_data) {
   
    // Split $field_data into separate $fields and $errors
    list( $fields,$errors ) = $field_data;
        
    // validate specific form
    if ( $form_data['id'] == 15 ) {
   
        // check at least one of required taxonomies set
        if ( empty( $fields['koopofhuur']['value'][0] ) ) {
   
            $errors['koopofhuur'] = 'Selecteer een item';
        }
  
    }
   
    return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'tssupp_require_sector', 10, 2 );

#2683406

Hi Waqar,

Thx for your reply.
I copied the code you provide into the custom code of mandatorytaxonomy.
I tested it in woondo.nl but it is not working.
Will you please assist.
Thx a lot.

Regards Loek

#2683579

I just tested the form on the 'Profiel Maken' page and the code does seem to be working.
( screenshot: hidden link )

Please note that other fields are natively set as required fields will show the error/validation message right away and won't let the form to submit.

But, the validation that is added through this custom code method, allows the form to be submitted, but if the validation is not successful, it stops the further process and shows the error message, as shown in my screenshot.