Search

I’m trying to build a simple form to filter my datasource. I have a datasource with the following filters for testing.

  • {$ref}
  • {$url-location}

when using GET the following will work and the data gets filtered….

<form name="input" method="get" action="">
    <input type="text" name="location" />
    <input type="submit" value="Submit" />
</form> 

But when I POST the following it doesn’t

<form name="input" method="post" action="">
    <input type="text" name="ref" />
    <input type="submit" value="Submit" />
</form> 

I’ve only started using symphony today so any help much appreciated.

the form markup attached

Attachments:
Screen shot 2009-12-22 at 23.59.23.png

I didn’t understand very well. What are you trying to do?

I’m trying to filter a datasource but it’s only working when I use GET and the param name is “url-variablename”. i’m trying to figure out why posting the values using the same form doesn’t work.

You’ll have to customize your Data Source to fit as your needs. Can you post it here? Use pastie for that.

Data Sources are located on workspace/data-sources/.

I’ve tried changing the param ‘$ref’ to $parameter-ref since

<?php

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

    Class datasourcejobs extends Datasource{

        public $dsParamROOTELEMENT = 'jobs';
        public $dsParamORDER = 'asc';
        public $dsParamLIMIT = '10';
        public $dsParamREDIRECTONEMPTY = 'no';
        public $dsParamSORT = 'system:date';
        public $dsParamSTARTPAGE = '1';
        public $dsParamHTMLENCODE = 'yes';

        public $dsParamFILTERS = array(
                '35' => '{$parameter-ref}',
                '33' => '{$url-location}',
                '43' => '{$url-role}',
                '44' => '{$sector}',
                '45' => '{$url-term}',
                '49' => 'yes',
        );

        public $dsParamINCLUDEDELEMENTS = array(
                'system:pagination',
                'ref-number',
                'job-title',
                'location',
                'salary',
                'job-description: formatted',
                'job-description: unformatted',
                'attach-logo',
                'term'
        );

        public function __construct(&$parent, $env=NULL, $process_params=true){
            parent::__construct($parent, $env, $process_params);
            $this->_dependencies = array();
        }

        public function about(){
            return array(
                     'name' => 'Jobs',
                     'author' => array(
                            'name' => 'Test Guy',
                            'website' => 'http://www.somedomain.com.localhost/symphony-2.0.6',
                            'email' => 'testguy@test.com'),
                     'version' => '1.0',
                     'release-date' => '2009-12-23T02:16:00+00:00');    
        }

        public function getSource(){
            return '9';
        }

        public function allowEditorToParse(){
            return true;
        }

        public function grab(&$param_pool){
            $result = new XMLElement($this->dsParamROOTELEMENT);

            try{
                include(TOOLKIT . '/data-sources/datasource.section.php');
            }
            catch(Exception $e){
                $result->appendChild(new XMLElement('error', $e->getMessage()));
                return $result;
            }   

            if($this->_force_empty_result) $result = $this->emptyXMLSet();
            return $result;
        }
    }

It is not possible to use POST values as Datasource filters without customising it. It isn’t particularly hard to do. Based on your example, you might change your grab() function to include this at the top:

public function grab(&$param_pool){
    $dsParamFILTERS['35'] = $_POST['ref'];
    ...

That will overload the filters with values before the DS uses it.

Just a quickie to say I think it’ll need to be:

$this->dsParamFILTERS['35'] = $_POST['ref'];

Otherwise it’ll set a local variable of $dsParamFILTERS not the object property :-)

Eh. Thanks Nick. You are correct.

If you don’t want to modify your data source by hand you can use the Global Parameter Loader extension to define a parameter. Define a parameter ref with value return $_POST['ref'];.

Remember that If you change a Data Source don’t forget to return false on allowEditorToParse function.

If you don’t want to modify your data source by hand you can use the Global Parameter Loader extension to define a parameter

I always forget about this extension! Great idea.

I always forget about this extension! Great idea.

I´ll just keep plugin it into every relevant discussion, hoping it will stick.

One tricky workaround I have done on a client site is to use POST to send all the data to a separate PHP file which then redirects based on a generated URL. The result filtering based on a form. Just link to your PHP form as per usual and have the URL be built based on the values from the form. You have to do a lot of if statements and concatenation but it works pretty well from my experience.

You can also use the Dynamic Event Redirect extension to redirect POST values to another Symphony-friendly URL.

Thanks for pointing out the Global Parameter Loader. I’ve modified the file for now and it works but I’ll certainly be looking into using that extension instead.

I’ve ran into some problems with the same search/filtering I’ve implemented above.

In a section that I created to populate the data source I’m filtering, I’ve used select boxes with dynamic options pointing to another data source. I was able to filter using the form above. However, the problem with this is that changing the value in the source of that select box doesn’t apply to the field within the data source I want to filter. So I’ve had to remove these and replace them with select box links instead.

After adding the same filters to the new fields I can longer get my search to work. Can anyone shed some light as to why I can filter a ‘select box’ but not a ‘select box link’ with the same text value. And how can I replicate what I had before with normal select boxes?

Can anyone shed some light as to why I can filter a ‘select box’ but not a ‘select box link’ with the same text value.

Select Box Link stores the target entry’s System Id, not its textual value. You may need to add another data source to fetch the entries you want by the textual URL parameter, and then returns IDs as its param output to use in filtering the original DS.

So, something like:

New Data Source
    Source: Target section
    Filter: Field = URL parameter
    Output: System ID

Old Data Source
    Filter: Select Box Link field = $ds-new-data-source

That’s a little convoluted, but I hope you get the point…

I’ve tried what you suggested but I still can’t seem to get it to work. Am I missing something?

Here are my data sources php files.

<?php

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

Class datasourcejobs extends Datasource{

    public $dsParamROOTELEMENT = 'jobs';
    public $dsParamORDER = 'desc';
    public $dsParamLIMIT = '3';
    public $dsParamREDIRECTONEMPTY = 'no';
    public $dsParamSORT = 'system:id';
    public $dsParamSTARTPAGE = '{$url-display-number}';

    public $dsParamFILTERS = array(
            '23' => '{$url-ref}',
            '26' => '{$url-salary}',
            '29' => 'regexp:{$url-description}',
            '57' => '{$url-role}',
            '56' => '{$url-sector}',
            '38' => '{$url-term}',
            '41' => 'yes',
            '59' => '$ds-new-data-source',
    );

    public $dsParamINCLUDEDELEMENTS = array(
            'system:pagination',
            'ref-number',
            'job-title',
            'salary',
            'bonus',
            'benefits',
            'job-description: formatted',
            'job-description: unformatted',
            'attach-logo',
            'role',
            'market-sector',
            'term',
            'eni-contact',
            'eni-contact-email',
            'published',
            'location',
            'region'
    );

    public function __construct(&$parent, $env=NULL, $process_params=true){
        parent::__construct($parent, $env, $process_params);
        $this->_dependencies = array();
    }

    public function about(){
        return array(
                 'name' => 'Jobs',
                 'author' => array(
                        'name' => '',
                        'website' => '',
                        'email' => ''),
                 'version' => '1.0',
                 'release-date' => '2010-01-18T20:37:57+00:00');    
    }

    public function getSource(){
        return '7';
    }

    public function allowEditorToParse(){
        return true;
    }

    public function grab(&$param_pool){
        $result = new XMLElement($this->dsParamROOTELEMENT);
        // If either post or get description is empty then remove regex filter
        if ($_REQUEST['description'] == ''){
            $this->dsParamFILTERS['29'] = '';
        }               

        try{
            include(TOOLKIT . '/data-sources/datasource.section.php');
        }
        catch(Exception $e){
            $result->appendChild(new XMLElement('error', $e->getMessage()));
            return $result;
        }   

        if($this->_force_empty_result) $result = $this->emptyXMLSet();
        return $result;
    }
}

And the new data source

    <?php

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

Class datasourcenew_data_source extends Datasource{

    public $dsParamROOTELEMENT = 'new-data-source';
    public $dsParamORDER = 'desc';
    public $dsParamLIMIT = '200';
    public $dsParamREDIRECTONEMPTY = 'no';
    public $dsParamPARAMOUTPUT = 'system:id';
    public $dsParamSORT = 'system:id';
    public $dsParamSTARTPAGE = '1';

    public $dsParamFILTERS = array(
            '35' => '{$url-region}',
    );

    public $dsParamINCLUDEDELEMENTS = array(
            'system:pagination',
            'region'
    );

    public function __construct(&$parent, $env=NULL, $process_params=true){
        parent::__construct($parent, $env, $process_params);
        $this->_dependencies = array();
    }

    public function about(){
        return array(
                 'name' => 'new data source',
                 'author' => array(
                        'name' => '',
                        'website' => '',
                        'email' => ''),
                 'version' => '1.0',
                 'release-date' => '2010-01-18T20:43:21+00:00');    
    }

    public function getSource(){
        return '11';
    }

    public function allowEditorToParse(){
        return true;
    }

    public function grab(&$param_pool){
        $result = new XMLElement($this->dsParamROOTELEMENT);

        try{
            include(TOOLKIT . '/data-sources/datasource.section.php');
        }
        catch(Exception $e){
            $result->appendChild(new XMLElement('error', $e->getMessage()));
            return $result;
        }   

        if($this->_force_empty_result) $result = $this->emptyXMLSet();
        return $result;
    }
}

Still no luck with this.

I’ve tried wrapping $ds-new-data-source with curly braces which seems to alter

$this->_dependencies = array();

to

$this->_dependencies = array('$ds-new-data-source');

This seems to work because it does return results. It just doesn’t apply the new-data-source filter {$url-region}

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