Skip Navigation

[Resolved] drop-down list of taxonomies, first choice

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

Problem:
How to set default option for taxonomy dropdown select
Solution:
You need to add custom jQuery or Javascript code to your CRED form's JS box to set default option for taxonomy dropdown select.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/drop-down-list-of-taxonomies-first-choice/#post-613116

Relevant Documentation:

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 20 replies, has 2 voices.

Last updated by massimoS527 6 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#613183

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What you mean when you say "I'm not able to use hooks"?

Here is the example - you need to add following code to your current theme's functions.php file and adjust the field name and code according to your needs:

add_filter('cred_form_validate','func_validate_taxonomy_select',10,2);
function func_validate_taxonomy_select($error_fields, $form_data)
{
    //field data are field values and errors
    list($fields,$errors)=$error_fields;
    //uncomment this if you want to print the field values
    //print_r($fields);
    //validate if specific form
    if ($form_data['id']==12)
    {
        //check my_field value
        if ($fields['wpcf-my_field']['value']!='correct_value')
        {
            //set error message for my_field
            $errors['wpcf-my_field']='Wrong Value';
        }
        //check if featured image exists
        if (empty($fields['_featured_image']['value']))
        {
            //set error message for featured image
            $errors['_featured_image'] = 'Missing featured image';
        }
    }
    //return result
    return array($fields,$errors);
}
#613200

I mean that I would really like to understand how to insert Hooks.

in your example there are items to change to adapt to my needs
example: id form.

where can I find a guide to learn how to use Hooks ONLY?

thank you

#613204

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I already shared the Doc link before for the hook Doc:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
[Click on "+ More" button to see examples ]

You can find CRED form ID when you edit your CRED form in URL.

#615225
Screenshot-2018-2-12 add-creatures – Riplove.png

Thanks Minesh,
I solved with the code you gave me

it would be nice to be able to CHANGE the field name in the error message.
It's not nice to see, example: "featured image error"

#615384

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that your original issue is resolved.

May I kindly ask you to open a new ticket with your each new question. This will help other users searching on the forum. Thank you for your understanding.

#615385

Sorry
🙂