Search

I’m making a website with vacancy’s on it. Visitors can filter the result of vacancy’s with a form and the GET method. For example by using url-params like this: http://www.website.com/?function=Worker

It works fine, but I don’t know how to filter more options (in this case functions) at the same time, like: Worker and Manager.

Does somebody know what I should do to make it work?

What happens if you seperate those terms with a comma? (for instance: Worker,Manager)?

http://website.com/?function=Worker,Manager

There’s a secton in the manual: Data Source Filters. It seems you’re looking for the and-operator: +.

Wow, that is a useful document, thanks!

@creativedutchmen - When I separate the functions with a comma, like you said: http://website.com/?function=Worker,Manager. The $url-function is: 'Worker,Manager' and no vacancy’s are showing up.

The problem continues when I use the and-operator '+' in this case the $url-function is: 'Worker Manager'.

@phoque - I’m aware of the way to filter data sources inside Symphony, but in this case I want to let the visitor filter the results using the form.

As the $url-function param is passed into the datasource for filtering, then it’s syntax needs to mimic the way datasources filter.

The + operator would fail as this is saying each entry needs to be both Worker and Manager. It should be , (comma) as this gives you Worker or Manager.

Have you tried manually filtering the ds like this to see if it returns entries? (i.e. writing Worker, Manager into the filter field?). How does the form filter the results? does it just pass it to the url which then reloads the page with that param intact?

Ok, I’ve just mimicked this and it works with , (comma) when using an url parameter passed into a datasource.

As this works as standard, you may have to explain your setup a little more. Can you do that and we’ll see what we can find out…

EDIT: Just a thought, try outputting a ds parameter as system id too. When you say that $url-function is ‘Worker,Manager’, what does the ds param show?

Hmm, I figured it out. I use now a , (comma) to search for Worker or Manager.
I didn’t know what I was doing wrong before but now it works.

Thanks for your help.

But now I want to show the visitor what they are filtering.
Inside the $url-function param stands 'Worker,Manager'. How do I separate these 2 words from each other and show them inside a list?
Like:

<ul>
<li>Worker</li>
<li>Manager</li>
</ul>

Use substring-before() and substring-after() XSLT functions. The separator is a “,” sign. The $url-function should be an argument to some template. In this template you write

<li>
<xsl:value-of select="substring-before($parameter,',')">
</li>

and then recursively evaluate the same template with an argument substring-after($parameter, ‘,’). Of course, you must add a termination condition in order not to get into an infinite recursion.

A little off-thought: XSLT must be a nightmare to those who are not familiar with functional programming…

A template like

<xsl:template name="split">
    <xsl:param name="string"/>
    <xsl:choose>
        <xsl:when test="contains($string, ',')">
            <li><xsl:value-of select="substring-before($string, ',')" /></li>
            <xsl:call-template name="split">
                <xsl:with-param name="string" select="substring-after($string, ',')" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <li><xsl:value-of select="$string" /></li>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

should do it. Call it with

<ul>
    <xsl:call-template name="split">
        <xsl:with-param name="string" select="$url-function"/>
    </xsl:call-template>
</ul>

Yeah, that’s a perfect imlpementation of my post above ;) Good job!

Guy’s thanks a lot, it works great!!

I’m using a basic form with an select field and a submit button. Only when I submit the form the output is like: http://website.com/?function=Worker&function=Manager and not like: http://website.com/?function=Worker,Manager as it should be.

How can I change this?

Does anyone know how to fix this?

Hm, you could try %2B instead of +.

How can I use %2B instead of +?

I’m now using this form method to submit the values to the URL:

<form id="zoekVacature" action="/werkgevers/cv-overzicht/" method="get">
    <fieldset>
        <select name="function">
            <option value="Worker">Worker</option>
            <option value="Manager">Manager</option>
        </select>
    </fieldset>
</form>

When I submit the form I get this output inside the URL:
http://website.com/?function=Worker&function=Manager

instead of:
http://website.com/?function=Worker,Manager

Can you post the full form you’re using, with how it’s submitted too?

This is the whole form.

<form id="zoekVacature" action="/werkgevers/cv-overzicht/" method="get">
    <fieldset>
        <select name="function">
            <option value="Worker">Worker</option>
            <option value="Manager">Manager</option>
        </select>
        <div class="button blue"><button type="submit" value="submit">Search</button></div>
    </fieldset>
</form>

Right.

I’ve been doing a little reading, and I can’t find any reference to multiselect form fields sending params as a comma separated list…

It seems to be that the what you’re seeing is correct… As far as I can see!

I’m really confused by this though as I thought they were supposed to be comma separated?!

EDIT:

I’ve done a full test on this now recreating the form in Symphony, with a section, DS and page, and I can agree that the behaviour isn’t as expected… Only the last param is passed to the data-source. I must admit, I assumed that it would be comma seperated. I’m also surprised that no one has brought this up before?!

Maybe this should be filed as a bug with the team, with regard to ds filtering. I would have thought that it should test for multiple params with the same name and array them…

On further reading, I’ve found that using a field name of function[] will pass the forms values into an array for processing in the back end (forms noob, can you tell?)

This creates some even more weird behaviour in the backend… When I use this method, the url-param is duplicated as $url-function.1 and $url-function.2 and so on…

Core team: Is this right? Shouldn’t Symphony concatenate them into a comma separated list?

This behaviour in Symphony is mostly to cater for Events. When you submit an event Symphony requires you send all of your field data in a fields array (namespacing it neatly so that it doesn’t interfere with anything else) e.g.

fields[title]
fields[description]

If you send this via GET (rather than the POST default for Events) you’ll see URL parameters in the form:

$url-fields.title
$url-fields.description

This is useful because it means you can use something like Form Controls (an XSLT library that creates input elements with the fields[name] for you) with GET variables as well.

So it looks like the intended behaviour should be to keep this convention, but if the array is un-keyed such as a multi-select that would create a GET URL such as:

/mypage/?field[]=x&field[]=y&field[]=z

then Symphony should not create three separate params as it does currently:

$url-field.1 = x
$url-field.2 = y
$url-field.3 = z

But it should create one param with commas:

$url-field = x, y, z

I think this would be fine in principle, but we’d need to make sure it wouldn’t break any existing implementations first. I can’t think of any sites I’ve worked on that rely on the numbered values.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details