MyBB Hacks

Full Version: Showing a selected value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working on a setup which shows the selected filter for one of my forums using XThreads. I have a working system, but it seems a bit clunky and I would like to know if there is an alternative method. I wanted to use this in another forum, but there are a lot of options.

In ths current forum I have one filterable field - fcat3

This is the code I am using for the dropdown and display:

HTML Code
<table border="0" cellspacing="{$GLOBALS['theme']['borderwidth']}" cellpadding="{$GLOBALS['theme']['tablespace']}" style="clear: both;">

	<tr>
		<td class="trow1" align="center">
			<form action="forumdisplay.php" method="get">
				<select name="filtertf_fcat3">
					<option value="">Select a Category</option>
					<option value="">All</option>
					<option value="Plugin">Plugin</option>
					<option value="Modification">Modification</option>
					<option value="ProPortalBlock">Pro Portal Block</option>
				</select>

<input type="text" class="textbox" name="search" size="35" value="{$searchval}" /> {$gobutton}
				<input type="hidden" name="fid" value="{$fid}" />
				<input type="hidden" name="sortby" value="{$sortby}" />
				<input type="hidden" name="order" value="{$sortordernow}" />
				<input type="hidden" name="datecut" value="{$datecut}" />
			</form>
		</td>

<td class="trow1" align="center"> Your Current Filters: 
<if ($mybb->input['filtertf_fcat3']==Plugin) then><span class="tea"> Plugin</span>  [<a href="forumdisplay.php?fid={$fid}">Clear filter</a>]
<elseif 
($mybb->input['filtertf_fcat3']==ProPortalBlock) then><span class="tea">ProPortal Block </span> [<a href="forumdisplay.php?fid={$fid}">Clear filter</a>]
<elseif 
($mybb->input['filtertf_fcat3']==Modification) then><span class="tea">Modification</span> [<a href="forumdisplay.php?fid={$fid}">Clear filter</a>]
<else>
All 
</if>
</td>
</tr>
</table>


As I said, it does work, but that is a lot of ifs. I am also unsure how secure that filter is. Advice and suggestions to improve appreciated. In case it is not clear what I mean, here is a link to the forum I am testing this display on:   http://www.leefish.nl/mybb/forum-51.html

HTML Code
<td class="trow1" align="center"> Your Current Filters: 
<if $filters_set['fcat3']['value'] then>
<span class="tea">{$filters_set['fcat3']['value']}</span>  [<a href="forumdisplay.php?fid={$fid}">Clear filter</a>]
<else>
All
</if>
</td>
</tr>
</table>


For reference purposes, can be done without a conditional too

HTML Code
<td class="trow1" align="center"> Your Current Filters: 
<span style="{$filters_set['fcat3']['visiblecss']}">
<span class="tea">{$filters_set['fcat3']['value']}</span>  [<a href="forumdisplay.php?fid={$fid}">Clear filter</a>]
</span><span style="{$filters_set['fcat3']['hiddencss']}">
All
</span>
</td>
</tr>
</table>


See Documentation/undoc.html for information on the $filters_set array.

Hmm, that is very similar to the first approach I tried, but the value is not showing in the display box now.

The filters work fine, but the displays are not showing - the display is at all.

The custom field is a textbox, it is set to everyone required. I have the default replacement value in as {value} and I also have a formatting map list:

Code:
Plugin{|}<a href="{$forumurl?}filtertf_fcat3=Plugin"><span style="color: green;"><strong>Plugin</strong></span></a>
Modification{|}<a href="{$forumurl?}filtertf_fcat3=Modification"><span style="color: green;"><strong>Modification</strong></span></a>
Theme{|}<a href="{$forumurl?}filtertf_fcat3=Theme"><span style="color: green;"><strong>Theme</strong></span></a>
Core File Edit{|}<a href="{$forumurl?}filtertf_fcat3=Core File Edit"><span style="color: green;"><strong>Core File Edit</strong></span></a>
ProPortalBlock{|}<a href="{$forumurl?}filtertf_fcat3=ProPortalBlock"><span style="color: green;"><strong>ProPortal Block</strong></span></a>

Oh, you've got it in the forumdisplay_searchforum_inline template.
In which case, you need to replace all instances of $filters_set with $GLOBALS['filters_set']
Oh DUH at me. I am sorry - I should have said it was in a different template, sorry about that. Yes, it is now working perfectly and in the way I expected.

Thank you.

Just edit to add: I went with the version from ZingaBurga with the if conditional as that way the clear filters option only showed if there was a filter in use.
Reference URL's