*** The krequest extender with alternative filter syntax and the maxFilter param description are here ***
Hi all
(Disclaimer: if you don’t understand the base of Ditto filtering && the anatomy of a request call, it’s difficult you’ll be able to understand this.
In that case,
RTFM about filtering and then
RTFM about the request extender.
Thx!)
I was playing with a form and noticed that it’s impossible to send filters to Ditto with request extender using fields not fixed.
For example, I can send a filter with a select, like
<label for="ditto_filter_1">News about:</label>
<select name="ditto_filter_1" id="ditto_filter_1">
<option value="topic,sport,1">Sport</option>
<option value="topic,economy,1">Economy</option>
<option value="topic,travel,1">Travel</option>
<option value="topic,science,1">Science</option>
</select>
Same for checkboxes
<input name="ditto_filter_1" id="ditto_filter_1" value="hasColor,red,7" type="checkbox" />Red
<input name="ditto_filter_2" id="ditto_filter_2" value="hasColor,blue,7" type="checkbox" />Blue
<input name="ditto_filter_3" id="ditto_filter_3" value="hasColor,green,7" type="checkbox" />Green
And, basically, with every type of
fixed single-or-multi choice field.
That’s because you can hardcode the filtering syntax. With a user-input field (like <input type="text" />) you can receive a value but not a complete filter (unless you teach the syntax to your users and have it directly inputed in the field).
This can be a problem if you (like me, obviously

) need to use a form with text fields to complex-filter a Ditto call with $_GETs.
So why don’t spice up a little bit the "filter on request" syntax? Yes! Who-o!
I’ve thought one solution: we can write part of the filter, the piece to describe the comparison (read: the TV and the numeric comparator), in the variable name and let the variable old the value we want to filter by.
Maybe an example is better than 10k words:
We have the old way to send filters (this is an piece of a $_GET url, just to highlight how the filters are passed: you can use $_POST too, it’s the same):
&ditto_id_filter_1=tvToCompare,value,3&ditto_id_filter_2=anotherTvToCompare,value,2
(the number after the value is just for the sake of the example)
But we can use an alternative way, where you can write the filter
in the variable name and let the user send only the value to compare against: let’s see the same call in the alternative syntax
&ditto_id_filter_1_tvToCompare3=value&ditto_id_filter_2_anotherTvToCompare2=value
As you can see, after the filter numbering (filter_1, filter_2) I’ve added an underscore and then the tv name (tvToCompare, anotherTvToCompare) AND, at the end, the numeric comparator (as told, in this case the numbers are for example).
Obviously the request extender can’t match this syntax with the regular request filter parser so I’ve created a modified request extender that includes the maxFilter param use: you’ll find informations on maxFilter and its use in
this post, along with the krequest.extender.inc.php
PAY ATTENTION
1) The filter numbering
must be preserved between normal and alternative syntax: the resulting of my piece of code is a normal filter, so if you use the same numbering for two filters written in different ways, the alternative syntax filter will replace the same-numbered normal filter.
Write every filter with a different increasing number!!! And respect the request filtering requirements (start with filter_1, then filter_2, and so on).
2) Under this code you can’t change the "localFilterDelimiter", because for the rush I didn’t check if that param is yet set at the time Ditto includes the extender so I optioned to create the filter inserting commas (",") as local delimiters as Ditto default behaviour.
Conclusions
Obviously this is a "fix" for a very remote situation, it works for me without problems but I suggest not to use it if you don’t work with complex forms as source for Ditto request filtering.
Obviously, it works for me. I’ve tested it but I don’t give warranty for anyone. Test it if you want to use it.
Mark, if it’s good for you, please put it in Ditto so I don’t have to modify the code every time you release a new version