search form and search url list display behavior

lcollong

FabriKant d'applications web
Hi,

I have a search form with two checkbox elts. If I check something in both elements, the resulted url looks ok (elt1[value]=bar&elt2[value]=foo) and the list display the right results. But if one of the element hasn't any box checked, the resulted url shows "elt1[value]=&elt[value]=foo" which sounds good but the filtered result is not.

What I want to achieve in this particular case is : "whatever is elt1 value, show all the records with elt2=foo".

Or, in case the user doesn't check any box at all and click on "search", the result should be the list displaying all the records rather than an empty list.

I've tried both with or without appending "&resetfilters=1" on the url. Also tried to set a default value to the search form element without any success.

Ideally, the constructed url should not include "&eltx[value]=" if no box is checked.

Where am I wrong ?
 
Assuming that this is the case, I've made a slight change to the redirect plugin in this commit:

https://github.com/Fabrik/fabrik/commit/89ff61457b4ce074562eb34cc03deec1f2f5a31e

... which adds a way of telling the code not to append an element to the query string if it's value is empty. HOWEVER ... I haven't yet actually enabled this feature, as I have a feeling it may cause issues with other aspects of search forms. So I need a Willing Volunteer to test it for me.

To test this feature, you'll need to update to the latest github, then edit that file, ./plugins/fabrik_form/redirect/redirect.php, and around lines 255 and 263 you'll find where we call $this->_appendQS():

PHP:
                    if (array_key_exists($name, $tmpData))
                    {
                        $this->_appendQS($queryvars, $name, $tmpData[$name]);
                    }
                    else
                    {
                        $element = $elementModel->getElement();
 
                        if (array_key_exists($element->name, $tmpData))
                        {
                            $this->_appendQS($queryvars, $element->name, $tmpData[$element->name]);
                        }
                    }

Modify those lines, to add a fourth argument (false) to those calls:

Code:
                    if (array_key_exists($name, $tmpData))
                    {
                        $this->_appendQS($queryvars, $name, $tmpData[$name], false);
                    }
                    else
                    {
                        $element = $elementModel->getElement();
 
                        if (array_key_exists($element->name, $tmpData))
                        {
                            $this->_appendQS($queryvars, $element->name, $tmpData[$element->name], false);
                        }
                    }

This should cause us to not append query string args for elements which have empty data.

See if this fixes your issue with checkboxes ... but ... if you could also test with other element types (like simple fields, joins, whatever) and make sure this doesn't mess with other usage of search forms, that would be very helpful.

Let me know what you find.

What I may have to do is add an actual option on the settings for the plugin, so you can specify whether you want empty data appended or not, rather than just doing it by default.

-- hugh
 
Hi Hugh,

Sounds great. As a first cut, it does solve this particular case. As a side effect, the resulted url does not show the "&elt[value]=foo" thing at the end, even if something is checked.... however the result is correct ! filtering is applied ?!?

ie : with the mods : the url shows : "index.php?option=com_fabrik&view=list&listid=12&Itemid=551&resetfilters=1" on the resulted filtered list whereas the url was : "index.php?option=com_fabrik&view=list&listid=12&Itemid=551&resetfilters=1&ens_t_formations___form_search_type[value]=PP&ens_t_formations___form_search_niveau[value]=03" on the original code. With the same search criteria.
I have to say that I've extracted and replace only the redirect.php file from the github. I didn't make a full update as my Fabrik version is no more than 2 weeks old.

Since it works, I stay on that for now and will make some further tests on different kind of fields as you suggest. I'll keep you inform.
 
Hmmm, strange. Doesn't look right. I'll enable the changes on my end as well, and do some testing.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top