Tagged: 

Viewing 3 reply threads
  • Author
    Posts
    • #3305
      Gregg
      Member

      Hi Steve

      Howzit going? Piklist is proving to be a great help on my current project – thanks! However, I’m running into an error with a simple widget that I created.

      The form consists of a single radio field with options. As a quick test, I added a line to display the value of that field …

      <?php echo $settings['gwfg_ratings_logo']; ?>

      … but get the following error when I drop the widget into a widget ready area on my site:

      Notice: Array to string conversion in /piklist/parts/widgets/gwfg-ratings-logo.php on line 14
      Array

      I’ve checked the forum and the docs, but can’t find any other way to correctly reference the selected value in the array. Any thoughts?

      Cheers,
      Gregg

      Attachments:
      You must be logged in to view attached files.
    • #3309
      Steve
      Keymaster

      @Gregg– Welcome to the Piklist community! Great to hear from you.

      List items (checkboxes, radio and select) are stored as arrays in the widget settings.

      For multi-select list items (checkboxes and select), loop over each item in the array:

      $radio_values = $settings['radio'];
      
      foreach ($radio_values as $radio => $value)
      {
        echo $value;
      }
      

      For Radio Buttons it’s easier. Just pull the first key.

      radio_value = $settings['radio'][0];
      
      echo $radio_values;
      

      Does this make sense?

    • #3312
      Gregg
      Member

      Works like a charm – thanks Steve.

    • #3313
      Steve
      Keymaster

      @Gregg– Great! Closing ticket.

Viewing 3 reply threads
  • The topic ‘Widget: Array to string conversion Error’ is closed to new replies.