• Hi Roland,
    Thank you for the great plugin.
    I’ve been trying to display images instead of strings in a list (a dropdown that was filled by user). Last time you said I have to use pdb-before_display_form_element.
    I read the docs and checked “Creating Custom Form Elements” example you’ve created in the documentation but I couldn’t customize it to my need.
    I coded the following but I don’t get the result I need. Where am I going wrong?

    add_filter('pdb-before_display_form_element','my_function', 10, 2);
    
    /**
     * @param array $fields
     * @return array
    */
    function my_function( $value, $field )
    {
       if (in_array('certificate name 1', $field->certificates))
    {
        $value = '<img src="path to cert logo 1" alt="">';
      }
    else if (in_array('certificate name 2', $field->certificates))
    {
      	$value = '<img src="path to cert logo 2" alt="">';
      }
    else {
      	$value = '<img src="path to non-existing logo" alt="">';
      }
      return $value;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author xnau webdesign

    (@xnau)

    It won’t be possible to display images in a dropdown like that. The HTML spec doesn’t allow it. You can find javascript that will do it, but you won’t be able to do it by inserting HTML tags into the values like that. You can do it with radio buttons or checkboxes, but not with dropdowns.

    Thread Starter iyogai

    (@iyogai)

    No, I think you misunderstood my question!
    I don’t want to use that in a dropdown. I wanna DISPLAY a number of selected items in a multi-select form element to normal users.
    If you take a look at my website https://www.iyogai.com, you’ll see that each record has a number of certificates. I’m trying to use an image instead of a text for each certificate to be displayed.

    Plugin Author xnau webdesign

    (@xnau)

    As far as I can tell, the best way to do this is with a custom template. You would have a field that holds the name of the image file, then in your template, the content of the field is use to display an image instead of the name of the file.

    You can try using an Image Upload field, but if you want to re-use images, you will need to edit the field values directly in the database because the image upload field is only for uploaded images. But if you put the path to an image in the value of the image upload field, it will show that image.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying images instead of array items’ is closed to new replies.