Search code examples
phphtmlformsexpressionengine

Support for URLs with GET parameters (query strings) in Expression Engine 2?


I'm developing an add-on for Expression Engine that has a search facility.

For search forms in the past, I've used a standard HTML <form> with its method attribute set to GET, and then server-side I'd parse this GET variables into some form of WHERE condition for a database query.

I'm trying to implement this logic in an Expression Engine add-on, but it seems Expression Engine does not like URLs with query strings, as when I submit the form the page breaks (it throws a 404 error).

Does Expression Engine support URLs with query strings? Or does this break the internal routing?

I should also mention that this add-on is to be implemented on many sites (the number unknown) and I'd like to stay away from making any changes to Expression Engine core files (i.e. PHP scripts) if possible, just in case this is suggested.

Thanks in advance.

EDIT: I thought I'd add some clarification as to what I'm trying to achieve.

In the past, I've used $_GET variables to drive search forms. So I may have a URL like:

http://example.com/search.php?size=large&color=red&page=1

As you can see, my query string contains name and value pairs as the parameters (including one for page) and these would created with a form whose action attribute is set to GET.

If there are $_GET parameters present, then search.php would parse this, formulate them into a SQL or XPATH query or whatever; and then return the matching records. The user could then page through these records by updating the page parameter that is present in the URL; the query would return just another portion of the result set as the other GET parameters would still be in the URL.

I want to achieve the same with an Expression Engine add-on. I want a form that takes the user-submitted criteria and then returns a record set that is pageable. I thought using a query string would be the best option given that it is RESTful and whatnot, but as aforementioned Expression Engine didn't like a query string being present in the URL, treated it as a different URL and threw a 404 error.

How can I create an add-on that generates a form, the submitted user is then used to query a database table, and results returned to the user that can then also be page?


Solution

  • It seems URLs with query strings work if there's more than one parameter in the query string, which seems absolutely backwards.

    So http://example.com/?foo=bar&baz=1 works, but http://example.com/?foo=bar does not.