Jump to content

Frontend filtering people advice


manlio
 Share

Recommended Posts

Hello I have a database of people that I wanna filter in the front-end.

Now in frontend I have two fields but maybe in future I wanna have more:

- Country (select tag)

- Surname (text field)

post-2575-0-83866900-1451471408_thumb.jp

If nothing is changed I would like to show the entire user list.

Now my problem is to understand which is the cleanest way to accomplish this in PW.

I send and sanitize two post variables ($inputcountry and $inputsurname), but I don't know how to cover all cases in a clean way.

For example if surname is empty this find doesn't work.

$instructors = $users->find("template=user,roles=$role,country=$inputcountry,user_surname*=$inputsurname,include=all");

Thank you!

P.S. Before I used only the country select and filtered users based on Urlsegment

Link to comment
Share on other sites

You can build your selector string like any normal string before you pass it to the find function. If a field has been left empty, you can simply not include it in the selector.

$selector = "template=user, roles={$role}, include=all"; //fixed part of the selector that is always used

if ($input->post('country')) {
    //sanitize etc.
    $selector .= ", country={$inputcountry}";
}

//repeat for other inputs
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...