Home › Toolset Professional Support › [Resolved] Help to change the returned error message
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 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/Hong_Kong (GMT+08:00)
Tagged: CRED API, Toolset Forms
Related documentation:
This topic contains 2 replies, has 2 voices.
Last updated by Robert Campbell 6 years, 7 months ago.
Assisted by: Luo Yang.
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
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';
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