0

Hi,

I am attempting to change a small piece of code in a forum I run but cannot figure out how to actually return the string of an item contained in an array instead of getting the items position in the array.
Sorry if this does not seem to be making much sense but let me post a small snippet of the code to try to help:

        array('select', 'pp_image_size', 'subtext' => $txt['pp_image_size_desc'], array('t', 's', 'm', 'l', 'x')),

The above code displays fine, exactly as it should, showing a drop down list called 'pp_image_size' and the list contains the relevent size strings 't' through to 'x'.

Now I am trying to use the above information to form a URL to grab a thumbnail image. The URL needs to incorporate a size variable, hence the drop down list. This is how the URL is formed:

      return '<img src="http://pagepeeker.com/thumbs.php?size=' . $modSettings['pp_image_size'] . '&url=' . $url . '" alt="" />';    

The problem I am getting is that the numerical value for the chosen strings position in the array is being used as the 'size' variable of the URL, which does not work.
What I need to do is actually have the string value of the size i.e. 't' and not '0', 's' and not '1' etc...

The finished URL should look like this, for example:

<img src="http://pagepeeker.com/thumbs.php?size=m&url=example.com" alt="" />

I really appreciate any help.

Edited by Cap'nKirk

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Cap'nKirk
0

Have a look at the code that creates the select field from the array. The value attribute of the options need to be:

<option value="t">t</option>
0

Thanks diafol for replying.

I did look at the regular 'option value' system as I use when coding forms in html but could not get it to fit the rest of the code.

Here is what I evetually came up with that works:

array('select', 'pp_image_size', array('[90x68]px', '[120x90]px', '[200x150]px', '[400x300]px', '[480x360]px')),

The above code creates the drop down list

This next piece of code works out which value has been selected and then forms the correct URL:

else if (!empty($modSettings['links_thumbs_provider']) && $modSettings['links_thumbs_provider'] == 4 && $modSettings['pp_image_size'] == 0)
      return '<img src="http://pagepeeker.com/thumbs.php?size=t&url=' . $url . '" alt="" />';

      else if (!empty($modSettings['links_thumbs_provider']) && $modSettings['links_thumbs_provider'] == 4 && $modSettings['pp_image_size'] == 1)
      return '<img src="http://pagepeeker.com/thumbs.php?size=s&url=' . $url . '" alt="" />';

      else if (!empty($modSettings['links_thumbs_provider']) && $modSettings['links_thumbs_provider'] == 4 && $modSettings['pp_image_size'] == 2)
      return '<img src="http://pagepeeker.com/thumbs.php?size=m&url=' . $url . '" alt="" />';

      else if (!empty($modSettings['links_thumbs_provider']) && $modSettings['links_thumbs_provider'] == 4 && $modSettings['pp_image_size'] == 3)
      return '<img src="http://pagepeeker.com/thumbs.php?size=l&url=' . $url . '" alt="" />';    

      else if (!empty($modSettings['links_thumbs_provider']) && $modSettings['links_thumbs_provider'] == 4 && $modSettings['pp_image_size'] == 4)
      return '<img src="http://pagepeeker.com/thumbs.php?size=x&url=' . $url . '" alt="" />';

Regards..,

0

The above code creates the drop down list

No it doesn't - it's just an array of values. That's what I wasa referring to - we need to see how the code uses this array to build the select dropdown.

0

Not to worry, I have it working anyway.

The code is from a page in an SMF Forum.

There are many, many places inside the Forum Admins settings where various settings are chosen via drop down lists.

I searched the entire forum software for 'option value' and it does not appear at all.

Once again, thanks for your help and I have it all working now.

Regards..,

MT

Edited by Cap'nKirk

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.