Multiple AdvSearchForm instances do not differentiate by asId parameter

I’d like to set up multiple date-range based advsearch forms. One would use datepickers to facilitate flexible date range queries, while others would query specific date ranges (e.g. this week, last week, etc.).

AdvSearchForm’s asId parameter is described as allowing for multiple search forms on the same resource, but it does not seem to function as intended.

Regardless of asId value used in distinct calls, every form renders with the default as0. Even the asId example calls in the documentation produce this outcome.

Second (and probably related), the form tpl of the first AdvSearchForm call is used by the second call (I currently have just two set up), regardless of what’s named as the latter’s form tpl.

Perhaps this due to the unmaintained nature of this snippet, but thought I’d post here to see if there are any ideas on how to troubleshoot. Thanks

I believe the problem is the call to $modx->getService() in the snippet AdvSearch. If a service with the same name (first parameter) already exists, the function ignores the current settings (4th parameter) and just returns the already existing class.

You probably can fix this by giving the service a unique name. Try changing this line in the snippet AdvSearch in the manager

to this. (This appends the value of the asId property to the service name.)

$$as = $modx->getService('advsearchrequest' . $as, 'AdvSearchRequest', $advSearchCorePath . 'model/advsearch/', $scriptProperties);

Then make a similar change to the snippet AdvSearchForm in the manager. Replace this line

with the line

$$asf = $modx->getService('advsearchform' . $asf, 'AdvSearchForm', $advsearchCorePath . 'model/advsearch/', $scriptProperties);

Your suggestions did the trick – thanks.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.