theoretic Posted January 31, 2018 Share Posted January 31, 2018 Hello there! And thanks for Processwire! It may appear a noob question but what about selectors like "field1=val1||field2=val2"? I mean that the page we're looking for should have field1=val1 OR field2=val2 . There's plenty of examples for cases like "field=val1|val2" but it's another case. Practical example: frontpage uder registration. User should enter nick and email, and both of them should be unused by other registered users. It's logical to use something like $userTest = $users->get("nick={$input->post->nick}|email={$input->post->email}"); But this doesn't work. That's the best practice in this case? Thanks in advance! Link to comment Share on other sites More sharing options...
BitPoet Posted January 31, 2018 Share Posted January 31, 2018 (edited) That's what OR-groups are for. $userTest = $users->get("(nick={$input->post->nick}), (email={$input->post->email})"); Btw., don't forget to sanitize your input before using it in selectors. Edited January 31, 2018 by BitPoet Example code was missing a comma 6 Link to comment Share on other sites More sharing options...
theoretic Posted February 1, 2018 Author Share Posted February 1, 2018 @BitPoet, thanks! It just works. But the syntax is far from being obvious. Maybe it could b a good idea to include "field1=val1|field2=val2" syntax in further PW releases. As far as i see it will not create conflicts with the existing selector syntax. Link to comment Share on other sites More sharing options...
zoeck Posted February 1, 2018 Share Posted February 1, 2018 9 minutes ago, theoretic said: As far as i see it will not create conflicts with the existing selector syntax. Theres a conflict Quote You may also specify an either/or value, by separating each of the values that may match with a pipe character "|". More details and examples can be found in the "OR selectors" section below. Its to separate different values of the selector... https://processwire.com/api/selectors/#values 1 Link to comment Share on other sites More sharing options...
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