Skip Navigation

[Resolved] Default value for taxonomy in cred form and unificate validation.

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

Last updated by alexG-11 2 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2259169

I want to validate with the same kind of error the taxonomy select with a custom default value and the other fields.
I follow this topic

https://toolset.com/forums/topic/cred-blank-empty-default-value-for-taxonomy-select-field/

For create a default value in a taxonomy field, but we need to unificate how display the errors.

How can we use the regular way of display not allowed empty field with toolset like the other fields?

Is there a better solution for this instead of use jQuery or vanilla?

#2259171

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

There are only two ways. The one that is by adding the custom JS and another one will be on server side validation using Toolset form's hook: cred_form_validate.

But I guess you are looking for frontend validation not server side, if yes, then you will have to go with the solution shared in the reference ticket you shared.

#2259177

This solution displays a totally different validation than the other fields. This field is html5 validation and the other toolset validation.

#2259191

Minesh
Supporter

Languages: English (English )

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

Can you please share details what kind of validation and error message you want to display and where you added the field and form on what page and share admin access details so I can check and review the current setup and see what we can do next.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2259879

Minesh
Supporter

Languages: English (English )

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

As I understand, you want to display the "This field is required" message but can you please share on what page/post you added the form and for what field you want to implement the required field validation?

#2262507

You need create an account with this form:

hidden link

Then you are redirected to the form with the error. The field is the first one "Disciplines". This has to be repeated in other forms so please explain how to achieve it.

#2262555

Minesh
Supporter

Languages: English (English )

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

But can you please confirm what validation you want to apply? What error message you want to display?

#2262615

Toolset over HTML5 error.

#2262647

Minesh
Supporter

Languages: English (English )

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

Can you please check now.

I've added the following filter code to your child theme's functions.php file:

add_filter('cred_filter_field_before_add_to_form', 'required_fields_func', 10, 1);
function required_fields_func($field){

 if(isset($_GET['cred_referrer_form_id'])) {
 $target_fields = array('Disciplines');
 
    if(in_array($field['title'],   $target_fields)){
         
       
       $required = array('required' => array(
                            'active' => 1,
                            'value' => true,
                            'message' => "This field is required."
                            ));
 
      $field['data']['validate'] =  $required;
        
          
    }
 }
    return $field;
}

To your form's JS box I've also added the following line:
=> hidden link

  jQuery("select[name='disciplina[]']").removeAttr("required");

So the code looks like:

jQuery(document).ready(function($) {
    jQuery("select[name='disciplina[]']").prepend('<option value="">Disciplina</option>');
    jQuery("select[name='disciplina[]']")[0].selectedIndex = 0;
   jQuery("select[name='disciplina[]']").removeAttr("required");});

Can you please confirm it works as expected now.

#2264801

My issue is resolved now. Thank you!