• Resolved pokerinabox

    (@pokerinabox)


    Hi,

    I’m exploring your list query object by writing custom code in my functions.php.

    I’ve seen your instructions/examples for setting up a form that handles a single search field, operator, and search term.

    Can you please elaborate (or point me to the appropriate support page) on how to do multi-search? I’m aware you sell a multi-search tool. But it looks like I can also just use your list query object to accomplish what I need.

    The missing piece for me is what to name the form controls and how to set the values in order to pass the query information to the next page (i.e. to be handled in the functions.php code)

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author xnau webdesign

    (@xnau)

    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

    Thread Starter pokerinabox

    (@pokerinabox)

    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 8 years, 3 months ago by pokerinabox.
    Plugin Author xnau webdesign

    (@xnau)

    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 8 years, 3 months ago by xnau webdesign. Reason: fix syntax
    Thread Starter pokerinabox

    (@pokerinabox)

    That works. Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘control names for multi-search?’ is closed to new replies.