Skip Navigation

[Resolved] CRED top error message customization

This support ticket is created 6 years, 7 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by Christian Cox 6 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#570596

Hello,

I am building a registration form with CRED and I need to customize the error messages on validation. I am using the cred_form_validate hook to customize the top error message appearing on the form after validation. There is one thing that I am struggling with:

I have a hierarchical category field called "Expertise Areas" with slug "expertise_area" set up with Types Taxonomy. I use the following piece of code in the cred_form_validation:

      $mytemp1=implode('',$fields['wpcf-expertise_area']['value']);
      if ( empty($mytemp1) ){
        $errors['wpcf-expertise_area']="Please select expertise area(s).";
      }

Here is what the top error message says on this:
"The post was not saved because of the following problem:
expertise_area: Please select expertise area(s)."

How can I get it to write the name (Expertise Areas) instead of the slug (expertise_area) of this field?

Thanks for your help!

#570780
Screen Shot 2017-09-17 at 12.10.09 PM.png
Screen Shot 2017-09-17 at 12.10.57 PM.png

In the Post Field editor, you can specify a Field Name that's different from the slug. The field name will be displayed in the error message for a custom field. See the attached screenshots.

#570818
Screenshot2.png
Screenshot1.png

Hi Christian,

Thanks for the quick answer. The field I am struggling with is a taxonomy. The regular fields defined with Types as post fields work fine. They display the field name as you say in the top validation window. But taxonomies do not. I defined a name for this taxonomy wich is "Expertise Area" (see screenshots attached), but in the validation window in the top of the CRED form, it displays the slug and not the name. I have the same problem with my other taxonomies. Is there any way I can force it to display the name and not the slug?

Thanks in advance!

#570844

Oh, I see what you mean here. If simply capitalizing the first letter of the slug is sufficient, you can add the following JavaScript code to your CRED form editor:

function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

jQuery(document).on('cred_form_ready', function() {
  jQuery('.cred-form .wpt-form-error > ul > li').each(function(index,item){
    jQuery(item).text(capitalizeFirstLetter(jQuery(item).text()));
  });
});
#570880

Hi Christian,

I changed your code into:

function capitalizeFirstLetter(string) {
    var string = string.replace("subject_area", "Subject area(s)");
    var string = string.replace("geographical_sector", "Geographical sector(s)");
    return string;
}
 
jQuery(document).on('cred_form_ready', function() {
  jQuery('.cred-form .wpt-form-error > ul > li').each(function(index,item){
    jQuery(item).text(capitalizeFirstLetter(jQuery(item).text()));
  });
});

And it displays what I want. But this is a work around. Can't CRED display directly and simply the actual name of the Taxonomy field?

Thanks.

#571045

I'll reach out to my 2nd tier support team to see if this is considered a bug, or if this is by design. It seems to me that, for consistency, the field name and taxonomy name should be used in both cases instead of slugs. Then you could format the name of the taxonomy how you would like it to display, and the errors would be formatted more consistently. Please stand by and I'll let you know what I find out.

#571403

Update - our 2nd tier supporters have escalated this to our developers as a consistency issue. I'll continue to update the ticket here as work progresses, but unfortunately I don't have a timeline available for implementation.

#581583

Hi, our developers have issued an erratum post about this problem, and plan to release a fix for it in the next version of CRED. I will gladly keep you posted here when the next version becomes available to test, or as a final release.
https://toolset.com/errata/wrong-taxonomies-custom-validation-message/

#588096

Hi, the latest release of CRED includes a fix for this issue. Please install CRED 1.9.3 and let me know if it's not resolved.

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