Skip Navigation

[Resolved] How to validate select taxonomy form

This support ticket is created 6 years, 4 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
- 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 3 replies, has 2 voices.

Last updated by Waqar 6 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1118981
2018-10-02_1645.png

In support tickets https://toolset.com/forums/topic/validate-select-taxonomy-form/

I still need assistance. I have sent you FTP information in the thread. Did you get my information?

#1119053

Hi there,

Thank you for contacting us and I'll be happy to assist.

We haven’t received the website’s access information with any of your tickets, but I’d like to share slightly updated code.

Can you please replace the old code from the active theme’s “functions.php” file, with this new one:


add_filter('cred_form_validate','validate_taxonomy_products',10,2);
function validate_taxonomy_products($error_fields, $form_data)
{
    //field data are field values and errors
    list($fields,$errors)=$error_fields;
    
    //validate if specific form
    if ($form_data['id']==25665)
    {       
        //check if any product taxonomy term is selected
        if (empty($fields['product-type']['value'][0]))
        {
            //set error message for empty product field
            $errors['product-type'] = 'Please select a product';
        }
    }
    //return result
    return array($fields,$errors);
}

Note: please make sure that “25665” matches the actual form’s ID.

Also update the code in the form’s “JS Editor” to:


jQuery(document).ready(function($){
 
jQuery("select[name='product-type[]']").prepend('<option value="">--- Select Product ---</option>');
jQuery("select[name='product-type[]']")[0].selectedIndex = 0;
  
});

In case the issue still persists, you’re welcome to share temporary access (WP-Admin and FTP) to your site, in reply to this message.

This access will allow us to offer better help and check if some configurations might need to be changed.

Your next answer will be private which means only you and our support team will have access to it.

If you’re going to share the access details for the live/production website, it is very important that a complete backup of your database and website has been made.

Please let us know how it goes and if you have any further information or questions.

Regards,
Waqar

#1119771

It works. Thank you! : )

#1119811

You're very welcome and glad it works 🙂

Thanks for the update and you can mark this ticket as resolved.

For the fastest assistance with a new question, please open a new ticket.

Have a great day!

regards,
Waqar