Suggest Fields is returning string and not array

About this forum
These forums have not been active for several years. They're available for search and reference, but a lot of this information is likely out of date.

For current information, try visiting our Knowledge Base.

Home / Support / Custom Module Development / Suggest Fields is returning string and not array

This topic is: resolved
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #53762

    davidlab
    Participant

    I am working with the ‘suggest’ field and it is returning a string and not an array of ids.

    The documentation says that the return value should be an array. However, like I said I am getting back a comma list of ids as a string. Is this a error in the docs? I want to make sure before I move forward with development.

    Thanks.

    #53805

    Justin Busa
    Keymaster

    Hey David,

    It looks like the docs are incorrect. I checked the code and I believe it’s returning a JSON encoded array of values. You should be able to do this to get an array in php…

    $my_array = json_decode( $settings->my_values );

    Let me know if that helps. I’ll get the docs updated.

    Justin

    #53856

    davidlab
    Participant

    Thanks Justin.

    #53874

    davidlab
    Participant

    Hey Justin, it is not working.
    I am using the ‘suggest’ to find tags from a custom taxonomy. That works fine and what is returned is a list of ids separated by a comma. It is not in JSON format…just a string (string ‘9, 7, 4’) and when I apply json_decode() I am getting a null return.
    The string value I am getting back is fine as a comma list as I can explode() it, but I want to make sure it is not a bug or other changes will be made to make my code break.
    Thanks

    #53992

    Justin Busa
    Keymaster

    Hey David,

    Sorry about that! At first glance it looked like a JSON encoded array but it is in fact just a comma separated string of the values. I’ve updated the docs to reflect that.

    Justin

    #54073

    davidlab
    Participant

    That fine Justin, my biggest concern was to clarify the correct output and not build around the wrong output. Thanks for the quick response.

    #54292

    Justin Busa
    Keymaster

    You’re welcome, David!

Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘Custom Module Development’ is closed to new topics and replies.