Skip Navigation

[Résolu] Help to change the returned error message

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

Make taxonomies fields as a required field in in Toolset form.
https://toolset.com/forums/topic/help-to-change-the-returned-error-message/#post-879154

Solution:

There isn't such a built-in feature within CRED,
As a workaround, you can create another custom field, for example "show-error-field", put it into the CRED form, and hide it with CSS codes, use it in your PHP codes, replace this line from:

$errors['member-arts-culture']= 'You must choose at least one category';

To:

$errors['show-error-field']= 'You must choose at least one category';

Relevant Documentation:

This support ticket is created Il y a 5 années et 10 mois. 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
- 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/Hong_Kong (GMT+08:00)

This topic contains 2 réponses, has 2 voix.

Last updated by Robert Campbell Il y a 5 années et 10 mois.

Assisted by: Luo Yang.

Auteur
Publications
#879154

I'm using the cred_form_validate function to require a user to select at least one taxonomy term on a front end post CRED form. I got the function from another support thread. The function is as follows:-

// Use to make it required for user to select at least one member category when adding new member
function member_require_category($field_data, $form_data) {
 
    // Split $field_data into separate $fields and $errors
    list( $fields,$errors ) = $field_data;
      
    // validate specific form
    if ( $form_data['id'] == 121 ) {
 
        // check at least one of required taxonomies set
        if ( empty( $fields['member-arts-culture']['value'] ) && empty( $fields['member-clubs-leisure']['value'] ) && empty( $fields['member-community']['value'] ) && empty( $fields['member-visit-dereham']['value']  ) ) {
 
            $errors['member-arts-culture']= 'You must choose at least one category';
        }
    }
 
    return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'member_require_category', 10, 2 );

The function works correctly but the error message is a bit confusing. It reads:-

'The post was not saved because of the following problem:

Members-Arts-Culture: You must choose at least one category'

So I want to remove the 'Members-Arts-Culture' from the error message. Is this possible?

I tried changing return array($fields,$errors); to return array($errors); but the error is not reported at all.

Your advice would be appreciated.

Regards

Robert

#881957

Dear Robert,

There isn't such a built-in feature within CRED, if you change the field slug, it will conduct unexpected result as you mentioned above: the error is not reported at all.

As a workaround, you can create another custom field, for example "show-error-field", put it into the CRED form, and hide it with CSS codes, use it in your PHP codes, replace this line from:
$errors['member-arts-culture']= 'You must choose at least one category';

To:
$errors['show-error-field']= 'You must choose at least one category';

#884955

Hi Luo

The wordaround worked perfectly. Thanks for your help.
Please add my vote to getting the facility to make taxonomies a required field in Toolset added as a new feature.

Regards

Robert

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