XF 2.1 Problem with filtering

Matt C.

Well-known member
Okay in my add-on I'm filtering between platforms.

190704

The filtering works, there's just a few issues. The first problem is that the URL doesn't change to matchmaking/&platform=PC, for example, when I hit the filter button.

The second problem is that sometimes when I reload I get a confirm form re submission notice.
190705

Here is the filter template code:

HTML:
<xf:macro name="filter_bar">
<div class="block-filterBar">
    <div class="filterBar">
        <xf:form action="{{ link('matchmaking') }}">
            <div class="inputGroup inputGroup--auto">
                <xf:select name="platform" value="{$params.platform}" class="input--autoSize">
                    <xf:option>{{ phrase('ah_mm_any_platform') }}</xf:option>
                    <xf:option value="PC">{{ phrase('ah_mm_pc') }}</xf:option>
                    <xf:option value="PlayStation 4">{{ phrase('ah_mm_playstation_4') }}</xf:option>
                    <xf:option value="Xbox One">{{ phrase('ah_mm_xbox_one') }}</xf:option>
                </xf:select>

                <xf:button type="submit">{{ phrase('filter') }}</xf:button>
            </div>
        </xf:form>
    </div>
</div>
</xf:macro>

I'm pretty sure there's something in the xf:form action part, but I'm not sure what to change.

Thank you to anyone who can help.
 
Might need to change the relevant line to <xf:form action="{{ link('matchmaking') }}" type="get"> though I'm not sure if that's the right value as I've never actually needed to switch to a get request for forms 🤔


Fillip
 
Might need to change the relevant line to <xf:form action="{{ link('matchmaking') }}" type="get"> though I'm not sure if that's the right value as I've never actually needed to switch to a get request for forms 🤔


Fillip

That doesn't do anything. :(

Could there be something wrong with this part?
Code:
public function actionFilters()
{
    $filters = $this->getMatchFilterInput();

    if ($this->filter('apply', 'bool'))
    {
        return $this->redirect($this->buildLink(
            'matchmaking', null, $filters
        ));
    }

    $showTypeFilters = true;

    $viewParams = [
        'filters' => $filters,
        'showTypeFilters' => $showTypeFilters
    ];

    return $this->view('AH\Matchmaking:Filters', 'ah_mm_filters', $viewParams);
}
 
Yes that worked! Thank you!

But I still have some issues.

The route is a bit weird, and the filter doesn't reflect the route.

190718
 
Try to view HTML source in your browser and see what is within
HTML:
<form>...</form>
tag.

I think there could be a kind of hidden input field, which explains the "_xfRoute" thing in your URL.
 
I think because your problem now is getting rid of _xfRoute, you can use normal <form> tag instead of <xf:form>.

Reference :

Now please try this one

HTML:
<xf:macro name="filter_bar">
<div class="block-filterBar">
    <div class="filterBar">
        <form action="{{ link('matchmaking') }}" method="get">
            <div class="inputGroup inputGroup--auto">
                <xf:select name="platform" value="{$params.platform}" class="input--autoSize">
                    <xf:option>{{ phrase('ah_mm_any_platform') }}</xf:option>
                    <xf:option value="PC">{{ phrase('ah_mm_pc') }}</xf:option>
                    <xf:option value="PlayStation 4">{{ phrase('ah_mm_playstation_4') }}</xf:option>
                    <xf:option value="Xbox One">{{ phrase('ah_mm_xbox_one') }}</xf:option>
                </xf:select>

                <xf:button type="submit">{{ phrase('filter') }}</xf:button>
            </div>
        </form>
    </div>
</div>
</xf:macro>
 
Sorry i don't know what variable contains the correct route value. :unsure:,

If you know it, you can add this somewhere within the <form> tag.
HTML:
<input type="hidden" name="_xfRoute" value="{$someVariableHere}" />

That still has that extra information in the route. It's fine tho, I can live with that. Do you know how to get the filter to reflect the route parameters?
 
Assuming the route parameter is $someVariableHere , you can use this HTML code

HTML:
<xf:macro name="filter_bar">
<div class="block-filterBar">
    <div class="filterBar">
        <form action="{{ link('matchmaking') }}" method="get">
            <div class="inputGroup inputGroup--auto">
                <xf:select name="platform" value="{$params.platform}" class="input--autoSize">
                    <xf:option>{{ phrase('ah_mm_any_platform') }}</xf:option>
                    <xf:option value="PC">{{ phrase('ah_mm_pc') }}</xf:option>
                    <xf:option value="PlayStation 4">{{ phrase('ah_mm_playstation_4') }}</xf:option>
                    <xf:option value="Xbox One">{{ phrase('ah_mm_xbox_one') }}</xf:option>
                </xf:select>

                <xf:button type="submit">{{ phrase('filter') }}</xf:button>
            </div>
            <input type="hidden" name="_xfRoute" value="{$someVariableHere}" />
        </form>
    </div>
</div>
</xf:macro>
 
That's not what I mean.

190720

In the template the value equals {$params.platform}. <xf:select name="platform" value="{$params.platform}" class="input--autoSize">

It's not getting the parameters from the route.
 
Top Bottom