• Resolved Miguel A.

    (@micheltron)


    Hi Abhishek, thanks for the plugin!

    I’m having some issues saving checkbox fields. The first is related to value encoding, the second is about how your plugin saves checkbox values to the database.

    For example, two checkbox values: “Hélix” and “Septum” are converted to [“H\u00e9lix”,”Septum”] in the database.

    First question: Why is the character é converted to Unicode \u00e9?

    Second question: ACF saves the checkbox values in post_meta table in an array like:
    a:2:{i:0;s:5:”Hélix”;i:1;s:6:”Septum”;}
    Why the checkbox values in custom table are saved in [“value 1″,”value 2”] format?

    If the field is radio, I have no issues with the value enconding.

    Thanks for your help!

    • This topic was modified 1 year, 4 months ago by Miguel A..
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Abhishek

    (@abhisheksatre)

    Hi,

    The conversion of the character é to Unicode \u00e9 is due to JSON encoding. Our plugin stores array data in JSON format. This encoding is employed as a best practice to ensure data consistency and prevent any potential character encoding issues during data storage and transmission. When you retrieve and display this data, our plugin uses the json_decode method to decode it.

    Regarding second question, the ACF plugin stores data in a serialized format, while our plugin stores data in JSON format. If you prefer to store data in the serialized format similar to ACF, you can achieve this by implementing a following filter. Once this filter is applied, our plugin will start storing data in the serialized format.

    add_filter('acf_ct/settings/serialize_array', '__return_true');
    Thread Starter Miguel A.

    (@micheltron)

    Thank you very much for your explanation and sorry for the late reply.

    When I try to retrieve the checkbox values using get_custom_table_field, the escaped Unicode characters are not decoded. Only by re-encoding the JSON I can get the value in UTF-8 format:

    $acf_value= get_custom_table_field (‘table’, ‘field’, $post_id);
    json_encode(json_decode($acf_value), JSON_UNESCAPED_UNICODE);

    Plugin Author Abhishek

    (@abhisheksatre)

    Hi,

    get_custom_table_field function provides the raw data from custom table. You will need to perform a decoding to get formatted results.

    Example

    <?php
    
    $value = get_custom_table_field (‘table’, ‘field’, $post_id);
    $formattedValue = json_decode($value);
    Thread Starter Miguel A.

    (@micheltron)

    Understood. It is clear now.
    Thank you for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Saving Checkbox values in DB’ is closed to new replies.