manlio Posted December 30, 2015 Posted December 30, 2015 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) 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
Jan Romero Posted December 30, 2015 Posted December 30, 2015 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 2
manlio Posted December 30, 2015 Author Posted December 30, 2015 Thanks Jan! This is what I was looking for. My php skill is really low, but this helps me to improve my coding. Thank you and happy new year!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now