Fix user search to support name, email, and phone
This commit is contained in:
parent
ef92c86fcc
commit
13554c1b02
1 changed files with 16 additions and 4 deletions
|
|
@ -35,6 +35,7 @@ if (len(query) < 3) {
|
||||||
try {
|
try {
|
||||||
// Detect if it's a phone number or email
|
// Detect if it's a phone number or email
|
||||||
isPhone = reFind("^[\d\s\-\(\)\+]+$", query) && len(normalizePhone(query)) >= 7;
|
isPhone = reFind("^[\d\s\-\(\)\+]+$", query) && len(normalizePhone(query)) >= 7;
|
||||||
|
isEmail = find("@", query) > 0;
|
||||||
|
|
||||||
if (isPhone) {
|
if (isPhone) {
|
||||||
// Search by phone - normalize both sides
|
// Search by phone - normalize both sides
|
||||||
|
|
@ -47,15 +48,26 @@ try {
|
||||||
", {
|
", {
|
||||||
phone: { value: "%" & phoneDigits & "%", cfsqltype: "cf_sql_varchar" }
|
phone: { value: "%" & phoneDigits & "%", cfsqltype: "cf_sql_varchar" }
|
||||||
}, { datasource: "payfrit" });
|
}, { datasource: "payfrit" });
|
||||||
} else {
|
} else if (isEmail) {
|
||||||
// Search by email
|
// Search by email (partial match)
|
||||||
qUser = queryExecute("
|
qUser = queryExecute("
|
||||||
SELECT UserID, UserFirstName, UserLastName, UserContactNumber, UserEmailAddress
|
SELECT UserID, UserFirstName, UserLastName, UserContactNumber, UserEmailAddress
|
||||||
FROM Users
|
FROM Users
|
||||||
WHERE UserEmailAddress = :email
|
WHERE UserEmailAddress LIKE :email
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
", {
|
", {
|
||||||
email: { value: query, cfsqltype: "cf_sql_varchar" }
|
email: { value: "%" & query & "%", cfsqltype: "cf_sql_varchar" }
|
||||||
|
}, { datasource: "payfrit" });
|
||||||
|
} else {
|
||||||
|
// Search by name
|
||||||
|
qUser = queryExecute("
|
||||||
|
SELECT UserID, UserFirstName, UserLastName, UserContactNumber, UserEmailAddress
|
||||||
|
FROM Users
|
||||||
|
WHERE UserFirstName LIKE :name OR UserLastName LIKE :name
|
||||||
|
OR CONCAT(UserFirstName, ' ', UserLastName) LIKE :name
|
||||||
|
LIMIT 1
|
||||||
|
", {
|
||||||
|
name: { value: "%" & query & "%", cfsqltype: "cf_sql_varchar" }
|
||||||
}, { datasource: "payfrit" });
|
}, { datasource: "payfrit" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue