Search

Firstly my apologies if this has been asked before, I have looked but can't find an answer, also apologies for any newbie questions.

I love what I have seen so far of symphony. I'm currently building a site for an estate agents and I am looking to create a property search.

At the moment I have a simple search working using get url parameters and filters in a data source. This is working for us great. However we do need to create a search that is more complex with a lot more options, which will make the url a little unwieldy with all of the extra get parameters.

So my question is - can I use a post form - I presume this would use events? To pass the search parameters through to a search results page? As far as I can see an event will save the search results to a section - is there anyway to not do this - as it is likely the database will grow very quickly if I save every search carried out on the site. Perhaps I need to create a custom event - something I would like to do but have little knowledge at the moment!

This site in your showcase; http://www.hotelbooking.co.mz is amazing and the search on the home page does exactly what I am looking for. Any pointers in the right direction would be gratefully received.

You certainly can post data through for a search, and convert it to the GET array using an event.

This will allow you to have clean urls, but the PHP behind Symphony will still create the $url-name style parameters for use in datasources.

It might also be beneficial to use ElasticSearch for more complex searching.

Thank you for the very quick response! This sounds great, sorry if it is a really stupid question but what do you mean by 'convert it to the GET array using an event'?

I have looked at Elastic search and it looks great - maybe I will implement this further down the line, I don't think it is needed at the moment for this particular project though.

Symphony uses Events to deal with data posted into a page, they run before page load on any pages they are attached to, so you could make a custom one to loop over the $_POST array, and add each one to the $_GET array before unsetting it in the POST.

If you have more detail on what you want, I'm sure we could come up with a starting point for you.

Thank you for your help, it is much appreciated. This is making a little more sense to me!

At the moment I have a simple form where the user can select property type, property price and enter property address. The get parameters are;

estate-sale-type (which is a select box with two fixed values, residential/commercial - the data source has this as a filter)

estate-sale-price-min and estate-sale-price-max (both of which are select boxes with a range of static prices - the data source has this as a filter such as {$url-estate-sale-price-min} to {$url-estate-sale-price-max})

estate-sale-address (this is an input box - the data source uses a regex filter for this)

Is this the detail you mean? Thank you so much for sticking with me on this, a pointer in the right direction would be really useful so that I know what I am doing is the correct way - as I am sure this will be needed for many more projects

What version of Symphony are you running too? When I know that, I can knock something up for you.

Thank you! I'm on symphony 2.3.1 for this site, but I can upgrade to 2.3.2 if needed.

Just wondering if anyone has any ideas on how to do the above? Any help will be gratefully received.

Really sorry, I completely forgot about this one :( I will try and get something for you later

no worries, thank you for sticking with me on this!

hello, my apologies I think my previous comment was a bit confusing! If you do have some spare time to post an example I would be most grateful. many thanks

Hello, I am returning to this project after it has been on hold for some time. I must admit I am struggling to get this to work. So far I have the following form code on my home page.

<form method="post" action="property-for-sale/?debug" enctype="multipart/form-data">
<select name="fields[property-location]">
    <option value="" selected="selected">Any</option>
    <option value="location1">location1</option>
    <option value="location2">location2</option>
    <option value="location3">location3</option>
    <option value="location4">location4</option>
    <option value="location5">location5</option>
    <option value="location6">location6</option>
</select>
<input name="action[submit-search]" type="submit" class="buttons" value="   Submit   " />

Attached to the property-for-sale page (the action) I have the following event code.

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

Class eventsearch extends Event{



    public $eParamFILTERS = array(

    );

    public static function about(){
        return array(
            'name' => 'Property Search',
            'author' => array(
                'name' => '',
                'website' => '',
                'email' => ''),
            'version' => 'Symphony 2.3.2',
            'release-date' => '2013-09-11T17:01:59+00:00',
            'trigger-condition' => 'action[submit-search]'
        );
    }

    public static function allowEditorToParse(){
        return false;
    }

    public static function documentation(){

    }

    public function load(){

        if(isset($_POST['action']['submit-search'])) return $this->__trigger();

    }

    protected function __trigger(){

        $page = Frontend::instance()->Page();

        foreach($_POST['fields'] as $name => $value){
            $_GET['fields'][$name] = $value;
        }

        unset($_POST['fields']);

        foreach($_GET['fields'] as $names => $values){
            $page->_param['url-'.$names] = $values;
        }


    }

}

When I view the url-params in the parameter pool of the debug window they are all there (i.e. action='property-for-sale/?debug'), however when I just use the page for the action of the form (i.e. remove the debug) and reference the variables in the xsl or in the data source filters they are just not there. I have probably made a major mistake somewhere, but any guidance or pointer in the right direction would be useful.

Basically I need a search form that uses post data to create parameters on the results page, so I am able to filter the results via a data source, if this is possible? I've updated the symphony version to 2.3.3 too

Thanks

Bump, anyone have any ideas...I need to be able to access post data on the search results page. Is this possible without using parameters in the url? I tried to loop over the post array and add them to the get array creating url-parameters but I can't seem to access them on the page. I am new to custom events and php POST etc so any help would be gratefully received.

Sorry, not got back to you on this.

If you trey running the Post -> Get conversion in the load method before the if statement, you shouldn't need to set the page params part of your trigger.

Hi, thank you for getting back to me.

Sorry, I may be missing something obvious but I have the following code and it doesn't appear to be returning anything;

public function load(){

        foreach($_POST['fields'] as $name => $value){
            $_GET['fields'][$name] = $value;
        }


        if(isset($_POST['action']['submit-search'])) return $this->__trigger();

    }

    protected function __trigger(){ 

        unset($_POST['fields']);

        return $result;

    }

Thanks again

Try

$_GET[$name]

I should have said, sorry (full of man flu).

Hi, thanks for coming back to me, I've tried;

$_GET[$name]

But it doesn't seem to be working, I'm probably missing the obvious somewhere. However this code does work, which I am happy to stick with so long as there are no glaring mistakes!

public function load(){

        if(isset($_POST['fields'])){

            foreach($_POST['fields'] as $name => $value){
                $_GET['fields'][$name] = $value;
            }
            unset ($_POST['fields']);

        }

        if(isset($_POST['action']['submit-search']))return $this->__trigger();

    }

    protected function __trigger(){

        $page = Frontend::instance()->Page();

        foreach($_GET['fields'] as $names => $values){
            $page->_param['url-'.$names] = $values;
        }


    }

I've amended the front end form and the results are coming through to the page now so I am able to filter them with the ds.

Thanks for all of your help, hope the man flu gets better soon!!

At least you've got it working. Sorry I couldn't get it right... Not very well achoo

No worries, you pointed me in the right direction. You help is much appreciated!

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