Start by taking a look at this page which goes into some detail on how to use the list query object:
The List Query Object
I’ve read through that page already. And it makes sense.
What I’m asking is what the names of the controls should be for the form?
For example, for searching a single first name I could do something like this:
<input name=”search_field” id=”pdb-search_field” class=”search-item” value=”firstname” type=”hidden”>
<input name=”operator” type=”hidden” class=”search-item” value=”LIKE” />
<input id=”participant_search_term” type=”text” name=”value” class=”search-item” value=”bob”>
but how do I do submit multiple search fields? what do I name the form controls such that they can be accessed on the next page (via the list query object)?
-
This reply was modified 9 years, 7 months ago by
pokerinabox.
Ok, that is up to you. The list query object does not access the form submission directly, you need to take the values out of the POST array and use them to add filters to the query object using the add_filter() method. That means you need to set up your form so that you can access all the search terms (and their associated field name) and then add them as filters to the query object.
For instance, if you wanted to have two search controls on two different fields, you could do it like this:
<input name="searchfield[]" type="text" value="" />
<input name="searchvalue[]" type="text" value="" />
<input name="searchfield[]" type="text" value="" />
<input name="searchvalue[]" type="text" value="" />
When that is submitted, in the post array you’ll have two arrays, one for the field names and one for the terms to use to search on those fields. Then you just add the filters using those values, something like this:
$query->add_filter( $_POST['searchfield'][0], '=', $_POST['searchterm'][0] );
$query->add_filter( $_POST['searchfield'][1], '=', $_POST['searchterm'][1] );
That’s not the way you’d do it really, I’m just showing you how the fieldnames work. Also, don’t use unsanitized values from the POST array, it is not safe.
The point is, those field names can be anything that makes it convenient for you to use the values out of the POST array and add your filters.
-
This reply was modified 9 years, 7 months ago by
Roland Barker. Reason: fix syntax