Skip Navigation

[Resolved] How do I change the error text associated with select2 in a relationship form

This thread is resolved. Here is a description of the problem and solution.

Problem:
I have a form to create a relationship between a Coach and a Trainee. If the user types into the select2 field(for either parent or child) a name that is already connected, the error message reads "No coach can be associated to [NAME]" or "No trainee can be associated to [NAME]"

This is terrible English and I want to be able to craft a better error message for the user. This message is not available in the Messages pane of the relationship form page. Where can I edit this text?

I also want to edit the placeholder text in the select2 (it current says "Search for a post")
Solution:

Relevant Documentation:
Another option: https://toolset.com/forums/topic/how-do-i-change-the-error-text-associated-with-select2-in-a-relationship-form/#post-2603489

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 4 replies, has 2 voices.

Last updated by amandaD 1 year, 8 months ago.

Assisted by: Mateus Getulio.

Author
Posts
#2602885
Screenshot 2023-05-04 170117.png
Screenshot 2023-05-04 170141.png

Tell us what you are trying to do?
I have a form to create a relationship between a Coach and a Trainee. If the user types into the select2 field(for either parent or child) a name that is already connected, the error message reads "No coach can be associated to [NAME]" or "No trainee can be associated to [NAME]"

This is terrible English and I want to be able to craft a better error message for the user. This message is not available in the Messages pane of the relationship form page. Where can I edit this text?

I also want to edit the placeholder text in the select2 (it current says "Search for a post")

What is the link to your site?
hidden link

#2602997

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Thanks for your contact!

You will find those texts in the \wp-content\plugins\cred-frontend-editor folder. For example, ( 'No %POST_TYPE_LABEL% can be associated to %OTHER_POST_TITLE%') can be found in the CRED_Association_Form_Front_End.class.php file, located in: \cred-frontend-editor\application\controllers\association_forms.

Please bear in mind that your modifications will be overwritten when you update the Toolset Forms plugin, and therefore you'll need to change the texts again. Also, be cautious when changing these files and always make sure to have a backup before doing this procedure.

I hope that the explanation above is clear and helpful to you, please let me know. Thank you.

Regards,
Mateus.

#2603299

Thanks - is there a way I can do it instead with a custom translation? In a PO file?

#2603489

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi Amanda,

Thanks for your reply.

In this case, we can suggest that you try the filter hook "gettext", in order to change the text according to your preferences. For example, you could add the below code into your theme/functions.php:

add_filter('gettext', 'my_func3', 10, 3);
function my_func3($translated_text, $text, $domain){
    if($text == 'No %POST_TYPE_LABEL% can be associated to %OTHER_POST_TITLE%' && $domain == 'wp-cred'){
        $translated_text = ''; // here you can change the text.
    }
    return $translated_text;
}

More info and help:
https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext

Note: the possible solution provided is to be used just as an informational one. Please remember that custom coding is out of the scope of our support, so we can't create, debug or modify code for you and it's your responsibility to maintain it. We hope the one we used as an example could point you in the right direction. Please check our support policy: https://toolset.com/toolset-support-policy/

Thanks for your understanding. If you need anything else don't hesitate to contact us.

#2603983

Brilliant, that worked perfectly. My issue is resolved now. Thank you!