Skip Navigation

[Resolved] Unable to make the checkbox mandatory on CRED

This support ticket is created 2 years, 8 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: Africa/Casablanca (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by himanshuS 2 years, 8 months ago.

Assisted by: Jamal.

Author
Posts
#2141765

I have followed the guidance in the code from here - https://toolset.com/forums/topic/cant-validate-checkboxes/

But, the checkbox is still not mandatory on this form - w.showprowess.com/expert-application/

Can someone please guide me on what I am missing?

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
function expert_mandatory_fields_check($field_data, $form_data) {
 
    // Split $field_data into separate $fields and $errors
    list( $fields,$errors ) = $field_data;
  
   $forms = array( 11422 );
    // check to see if this is the correct form 
    if ( in_array( $form_data['id'], $forms ) ) {
       
      if ( !isset($fields['wpcf-expert-self-reported-skills']['value'][0]))
        $errors['checkboxes'] = 'Please select at least one skill you can evaluate';
    }
       
    return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'expert_mandatory_fields_check', 10, 2 );
#2141907

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting Toolset support.

The code seems correct to me. It will need some debugging to spot the issue. Can I log in to your website and check it further? Your next reply will be private to let you share credentials safely. I'll need FTP access too. ** Make a database backup before sharing credentials. **

If I needed to debug further, I'll have to work on a copy of your website on my local development environment. Let me know if that's fine with you.

#2142583

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I confirm that the credentials are working for me. However, I could not find the code snippet. Can you tell where the code is being added?

#2142769

Jamal,
My bad. The code snippet is in the toolset custom code tab.

Name: make-expert-fields-mandatory

hidden link

Also, I am seeing the following error on page load. Not sure if it is related - Uncaught ReferenceError: wptCondCustomTriggers is not defined
at (index):973

#2143003

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

The issue within the code is on line 22. The code should be:

$errors['expert-self-reported-skills'] = 'Please select at least one skill you can evaluate';

Instead of:

$errors['checkboxes'] = 'Please select at least one skill you can evaluate';

We need to use the field's slug as the key in the errors array.

Regarding the new error that you encounter, please open a new ticket and let us know what steps we should follow to see the error, and we'll do our best to help.

#2143139

Thank you, Jamal. I appreciate the support!

#2143141

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.