I have created a custom registration form, and I am attempting to register members to my site by
(a) adding data to my custom collection and CRM at the same time;
(b) checking that user has not been registered before; and
(c) on successful registration navigate to a different page.
Adding data to CRM & navigating to a different page does not work. I’ve searched the forum and compared my code to the API but I cannot see where I am going wrong.
Any advice appreciated.
import wixUsers from 'wix-users';
import wixLocation from "wix-location";
import wixData from "wix-data";
$w.onReady(function () {
$w('#submitRegistration').onClick(() => {
let enteredEmail = $w("#email").value;
let formattedEmail = (enteredEmail).toLowerCase();
console.log(formattedEmail);
wixData.query("regClients")
.eq("registerEmail", (formattedEmail))
.limit(1)
.find()
.then((results) => {
let databaseEmail = results.totalCount;
console.log(databaseEmail);
if (databaseEmail === 0) {
wixUsers.register((formattedEmail), $w('#password').value,
contactInfo: {
"company": $w('#company').value,
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
"phones": $w('#mobilePhone').value,
"category": $w('#category').value,
}
})
.then(() => {
console.log('Registration completed.');
let url = `https://dean15224.wixsite.com/unsquaredaccounting/client- onboarding-checklist`
wixLocation.to(url);
})
} else {
console.log("User not registered.");
$w("#checklistReturn").expand();
$w("#registerFailtext").expand();
}
});
});
});