Search

I see a couple of ways to accomplish your goal. You could use javascript to concatenate selected parameters, but I would go with another approach.

You could use an event like this and forget about javascript. Make sure that $elementName is the name of your select (without []: in your case function[] became just function) and it should work.

It works for me with this html:

<form id="zoekVacature" action="/werkgevers/cv-overzicht/" method="get">
    <fieldset>
        <select name="function[]" multiple="multiple">
            <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>

Thanks for the explanation Nick, still a little confused, but if I read it a couple of times…

Marco, I would never have thought about events, as it’s not posting into a section. Great solution though! Cheers…

Edit:

Quick question though, I don’t understand this bit:

const ROOTELEMENT = 'test';
public $elementName = 'name';

What is the ROOTELEMENT for? And do we have to hardcode the $elementName?

The ROOTELEMENT is ininfluent, you can remove it, and yes $elementName is hardcoded. Making it work for each un-keyed array parameter would be a snap but, as Nick pointed out:

… we’d need to make sure it wouldn’t break any existing implementations first

That’s perfectly understandable to prevent breaking things. As it’s an event, the user could just attach it to pages that they want it on though right?

I’m just trying to think of a ‘general’ solution, doing a foreach on the $GET to check whether any $GET variable is an array and then create an url param for each one…

My PHP is crap though ;o) Would something like this work, although I get stuck in the __trigger

public function load(){
        $trigger = false;
        foreach($_GET as $getParam){
            if(is_array($getParam)) $trigger = true;
        }
  if ($trigger) return $this->__trigger();
}

protected function __trigger(){
  $page = Frontend::instance()->Page();
      foreach($_GET as $getParam){
        // This is where I get stuck...
        $page->_param['url-'. $this->elementName] = join(',', $_GET[$this->elementName]);
      }
}    

You should determine if a parameter is an associative array or not. Something like this works for me.

I was just about to post something very similar, only without the associative array test…

Yours is better ;o)

The good thing about using this event is that the serialized url-params are still present, this just creates a new one as a comma separated list, so I don’t reckon it would break anything relying on the serialisation.

Am I right in thinking that?

This would make a very useful extension Marco. Do you want to do it? I don’t want to steal your work…

PS, I’m sorry to take over Mark’s (whgdesign’s) post here, at least we have found a solution though…

I tried to solve the problem with the event. I did the following:

I changed my form into:

<form id="zoekVacature" action="/werkgevers/cv-overzicht/" method="get">
    <fieldset>
        <select name="function[]" multiple="multiple">
            <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>

Then I’ve made the event with:

<?php

    require_once(TOOLKIT . '/class.event.php');

    Class eventmultisearch extends Event{

        const ROOTELEMENT = 'multisearch';
        public $elementName = 'function';

        public $eParamFILTERS = array(

        );

        public static function about(){
            return array(
                     'name' => 'Multisearch',
                     'trigger-condition' => 'action[multisearch]'); 
        }

        public static function allowEditorToParse(){
            return false;
        }

        public static function documentation(){
            return '';
        }

        public function load(){
            if (isset($_GET[$this->elementName])) return $this->__trigger();
        }

        protected function __trigger(){
            $page = Frontend::instance()->Page();
            $page->_param['url-'. $this->elementName] = join(',', $_GET[$this->elementName]);
        }       

    }

I called the event event.multisearch.php and attached the event to the page.

When I run the form the output looks like:
/werkgevers/cv-overzicht/?function[]=Worker&function[]=Manager

but it should be:
/werkgevers/cv-overzicht/?function=Worker,Manager.

Can you tell me what I’m doing wrong?

The URL won’t change, but this makes another $url-param in the backend which is a comma separated list. You can then use that to filter the datasources of your choice.

Append &debug=params to the end of the url to see what I mean…

Okey, I see now the params $url-wensenfunctie.1 and $url-wensenfunctie.2

When I have for example 50 options, should I have to make 50 filter options inside the DS, or is there a way to make one filter option?

If the event is working right there should be $url-wensenfunctie.1 and $url-wensenfunctie.2 and also $url-wensenfunctie nearer the bottom of the list. The latter will be the comma separated list.

The numbered ones will be there and will be as many options you have. There should be no reason to add more then the single filter to the ds.

This was my version of what Marco wrote for us, which I know works, as I’m now using it.

As for the extension, if you have time, go and release this!

Cool beans, will do (your name will be all over it though ;o))

For some reason Symphony cannot accept a + as a url param? I've tried just + and %2B, but the param comes out as something another instead of something+another.

This is the correct behaviour. You should google URL encoding.

I did google it. The top StackOverflow answer says to use %2B when passing a plus character to a parameter. It works in other PHP applications but not in Symphony.

Sorry, I was unprecise and actually meant s.th. different.

A blank character in a query string is encoded as a plus. You can try that here: http://www.w3schools.com/tags/ref_urlencode.asp (the third Google result). So if you have ?tags=big+blue as query string, the value actually is the literal string big blue. If you want big and blue as values, you use a comma, like so: tags= big,blue. In Symphony, this is correctly decoded. However, the latter will be interpreted as big or blue by the datasource filter.

As I said, I am not using ?tags=big+blue but ?tags=big%2Bblue, which is correct according to

http://stackoverflow.com/questions/4763917/how-can-i-replace-the-plus-sign-with-its-corresponding-url-encoding-of-2b http://stackoverflow.com/questions/7842547/request-parameter-losing-plus-sign http://stackoverflow.com/questions/1373414/ajax-post-and-plus-sign-how-to-encode

but the param comes out as big blue still, even though the + is encoded to %2B

BTW I'm purposely trying to get the and functionality, not or. I am able to use , for or just fine.

Confirmed, there are actually two bugs here.

Please post any new findings on the bug tracker.

I've been trying all day to get URL parameters with multiple values to work. At the moment I have a series of checkboxes and a submit button. On submit the form goes to another page where I am able to pick up the parameters.

As described above I only get the last parameter added to the param pool and my url looks like this;

animal-selection/?enquiry%255B%255D=27&enquiry%255B%255D=28

If I manually separate the values with a comma like this;

animal-selection/?enquiry%255B%255D=27,28

They both appear in the param pool. I just don't know how to add in the illusive comma.

I have tried using the [] brackets for the checkbox name but this hasn't worked. I have taken the exact code above with the option select boxes and added the event but still no luck.

Does anyone have any suggestions - I am using Symphony 2.3.2.

Many thanks in advance, I'm most likely doing something wrong but it's driving me crazy!

You will probably need to manipulate the GET array. Try something like the code posted by @deginermonkey.

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