Skip Navigation

[Resolved] requested multi choose field

This support ticket is created 6 years, 9 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.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 9 months ago.

Author
Posts
#660445
Schermata 2018-04-13 alle 21.15.24.png

I need a requested multi choose field in order to select the tipology of itinerary (custom type). I started with "Select" field but it didn't support multi choose despite it managed requested! So I switched to "Checkboxes" that let me multi choose but it didn't support requested. This solution could be good enough. I have some question:
1) is there a way to get checkboxes field requested?

2) in DB I have this data saved for the itinerary "Pescara e le Leggende della Formula Uno"
a:4:{s:64:"wpcf-fields-checkboxes-option-a04dc42b6690b9394e5e56a84cf4682e-1";i:0;s:64:"wpcf-fields-checkboxes-option-f15c315141e2fc030659b771d8d7ba1e-1";a:1:{i:0;s:7:"In bici";}s:64:"wpcf-fields-checkboxes-option-a96fe960e621ef64b9273a3f2187a6f4-1";i:0;s:64:"wpcf-fields-checkboxes-option-8e000be9e4aa24339cf8bfbd68b697e1-1";a:1:{i:0;s:18:"Trasporto pubblico";}}
I read this value from SQL query and return that data. How can I parse it, client side, in order to get every single checkbox value ("In bici" or "Trasporto pubblico"?

3) At the moment I need to know how to translate Checkboxes field, but if possible, please anticipate me something about how to translate all contents created with Toolset because, soon, I'll need to translate my web site in English.

Thanks and Best regards,
Danilo

#664437

Is there a way to get checkboxes field requested?

No, there is no way in the Toolset GUI to make the Checkboxes Custom Field "required" in the Post edit screen.

Possible solutions here are for example to validate it with custom JS, or to apply a custom script which saves some default values in case nothing is set, by hooking in save_post() and addressing the Custom Field with update_post_meta().

But this requires custom code on a level that we cannot support here.
The DOC to consult is this
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
https://codex.wordpress.org/Function_Reference/update_post_meta

Or, you can add the Field to a CRED form.
In a CRED form then you can validate it using the CRED API:
https://toolset.com/forums/topic/cant-validate-checkboxes/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

in DB I have this data saved for the itinerary "Pescara e le Leggende della Formula Uno":
(serialized array)
I read this value from SQL query and return that data. How can I parse it, client side, in order to get every single checkbox value ("In bici" or "Trasporto pubblico"?

That depends what you want to do.
The field is already automatically displayed in the WordPress backend when you edit the post.
You can display it with the ShortCode for it, which you can find in any Text Editor in the Toolset GUI if you press the "Fields and Views" button.

To manipulate this specific field with Code, you need advanced PHP knowledge.
I have an example snippet here that should give you an insight:
https://pastebin.com/wz6dQVBE (starting line 23)
As you see checkboxes are not a simple value, it's an array of array.

What we suggest is to populate it the way it's intended to (with the GUI) and display it with the ShortCodes or our API:
https://toolset.com/documentation/customizing-sites-using-php/functions/

At the moment I need to know how to translate Checkboxes field, but if possible, please anticipate me something about how to translate all contents created with Toolset because, soon, I'll need to translate my web site in English.

Please refer to WPML for this task, it's what we suggest to use:
https://wpml.org/

However, Checkboxes are complex - as well to translate.

If I may add a final suggestion, then it would be to "do not use checkboxes".

Use something else. You will have fewer complications in future if you use a Taxonomy, or Select Field instead.