Supply extra parameter to autocomplete according to Zend Framework

ajax, javascript, jquery, php, zend-framework

Solution

This is one of those 'gray areas' where using the server to generate the Javascript could work against you. Writing the client-side script yourself would benefit you in a number of ways:

- You'll learn more about jQuery Autocomplete and what you can do with it.

- You'll have greater control over the behaviour of the autocompleter.

- Your solution will be less dependant on the Zend Framework, and will thus be more portable.

I would familiarise myself with the addition parameters on the jQuery side of things, before looking at `ZendX_JQuery_Form_Element_AutoComplete` as the end-to-end solution. Also, you might want to read the following essay by Joel Spolsky entitled "The Law of Leaky Abstractions" if you haven't already:

http://www.joelonsoftware.com/articles/LeakyAbstractions.html

I've implemented an autocompleter (tied to a ZF controller action) and was fully aware of the existence of ZF's autocomplete helper, but chose not to use it, as I did not want to be in one of those situations where applying a minor tweak would necessitate scrapping the entire solution because the code generation tool on the server doesn't want to play.

Hope that was more helpful than annoying.

Problem

I have a form with (at least) the following two fields: - country - club The club is a field that is generated via the ZendX_JQuery_Form_Element_AutoComplete Element, that also generates the following javascript code: ``` $("#club").autocomplete({"url":"\/mywebsite\/\/mycontroller\/autocomplete"}); ``` I have a database of clubs per country. What I want is that only the clubs are returned for the (user) given country. This list should be retrieved via a remote (ajax) call. The code for that is: ``` public function autocompleteAction() { $request = $this->getRequest(); $filter = $request->getParam('q'); $country = $request->getParam('country'); $clublist = getClubListBySubstring($country, $filter); $this->_helper->autoComplete($clublist); } ``` I can probably change the above javascript-code, by-passing the generation done by ZendX_JQuery_Form_Element_AutoComplete and add an extra element to the URL that gets interpreted as parameter country . But is there a more elegant solution? I've read something about ExtraParams, would that work, and how?

Original source