Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: The Wizard - helmikuu 12, 2014, 01:53:37 IP

Otsikko: select box changes url
Kirjoitti: The Wizard - helmikuu 12, 2014, 01:53:37 IP
Hello:

This is the select box code I am using -

if (!empty($context['toy_shop_inv']['categories']))
{
echo '
<form action="', $scripturl, '" method="get">
<input type="hidden" name="action" value="', $context['toy_shop_link_value'], '" />
';

echo '
<strong>', $txt['toy_shop_category'], ': </strong>
<select name="cat">
<option value="-1"', ($context['toy_shop_inv']['category'] == -1 ? ' selected="selected"' : ''), '>', $txt['toy_shop_cat_all'], '</option>
';

foreach ($context['toy_shop_inv']['categories'] as $category)
echo '<option value="', $category['id'], '"', ($context['toy_shop_inv']['category'] == $category['id'] ? ' selected="selected"' : ''), '>', $category['name'], '</option>';

// Do not remove echo below as it change the GO button placement
echo '</select><input type="submit" value="Go" /></form><br clear="all" />';
}



This link "view_a_friends_toy_room_part_2;member=Rat " is sent to the select box using this code.
$context['toy_shop_link_value'] =  'view_a_friends_toy_room_part_2;member=' . $member['name'];

when a option is selected from the select box the following link is out putted -
"view_a_friends_toy_room_part_2%3Bmember%3DRat&cat=501"

I need the output to look like this -
"view_a_friends_toy_room_part_;member=Rat&cat=501"

any idea how to do this?

Wiz


Otsikko: Re: select box changes url
Kirjoitti: The Wizard - helmikuu 13, 2014, 08:37:04 AP
anybody??
Otsikko: Re: select box changes url
Kirjoitti: All Colours Sam - helmikuu 13, 2014, 11:27:38 AP
Yo're telling the form to go to the forum index:

<form action="', $scripturl, '" method="get">

I don't really know what you're trying to achieve here, the link is outputted where?

Where doe this code come from?

$context['toy_shop_link_value'] =  'view_a_friends_toy_room_part_2;member=' . $member['name'];

???

How are you printing the link?  via what? to where?
Otsikko: Re: select box changes url
Kirjoitti: The Wizard - helmikuu 14, 2014, 09:59:14 AP
To: Suki

Thank you I really appreciate all the help and support. I don't think I would have gotten as far as I have without you and everybody else who has helped me. Again Thank you everybody.

After 2 days of research, and a few dozen approaches the light bulb went off - I don't need to use a select box. I could use a link design instead. I was only using the select box because it was left over from the original code.  Since I had lots of space for links it was a easy fix and it makes the categories more pronounced then just a select box.

So I'm Happy.

Wiz

Below is a copy of my link code just in case anybody needs it:


function toy_shop_categories()
{
global $txt, $context, $scripturl;

echo '
<br />
<div class="cat_bar">
<h3 class="catbg" align="center">', $txt['toy_shop_categories'], '</h3>
</div>
<br />
<center>
<table>
<tr>
<td>
';

echo '<strong><a href="'. $scripturl . $context['toy_shop_link_value'] . ';cat=-1">', $txt['toy_shop_category_all'],'</a><br /></strong>';


if (!empty($context['toy_shop_inv']['categories']))
{
foreach ($context['toy_shop_inv']['categories'] as $category)
echo '<strong><a href="'. $scripturl . $context['toy_shop_link_value'] . ';cat='. $category['id']. '">', $category['name'], '</a><br /></strong>';
}

echo '
</td>
</tr>
</table>
</center>
';
}