Hello,
I’m wondering if someone could help look at my registration code. My website sends the information to the contacts page in the CRM and the form submission dataset, but it is not registering a member. My members setting is set to “anyone can join,” so the registration should go through automatically, but as of now, the only way I can register members is to do it manually through the contacts setting: set contact as members.
I also tried to do the registration on the back end, which is preferable because it is more secure, but I couldn’t get that to work either. So I tried to rely on the front-end code in good faith that the security is intact because of the “anyone can join” setting as noted in the documentation.
I am familiar with Java but haven’t worked with much JavaScript and the WIX / Velo API is new to me.
I’ve been all over the WIX API documentation for weeks and still cannot get it to work. I realize it’s probably a small error, but I can’t seem to find it.
I don’t have any acquaintances who do any sort of coding so I really have no one else to show my code.
I really, really appreciate any help!!
The code follows:
$w.onReady(function () {
$w('#submitButton').onClick(
() => {
let firstName = $w('#firstNameField').value;
let lastName = $w('#lastNameField').value;
let email = $w('#emailField').value;
let dateOfBirth = $w('#dateOfBirthField').value;
let country = "US-";
let state = $w('#dlStateField').value;
let dlNumber = $w('#dlNumberField').value;
let password = $w('#passwordField').value;
var applicationType = findApplicationType($w('#newOrUpgrade').selectedIndex);
let tprStateCode = country + state;
let termsCheckbox = $w('#termsCheckbox').checked;
emails.push(email);
let radioIndex = $w('#newOrUpgrade').selectedIndex;
console.log("Radio index is " + radioIndex);
function findApplicationType(radioIndex) {
if ((radioIndex === 0) || (radioIndex === 1)) {
applicationType = "new";
newOrUpgrade.push(applicationType);
} else if (radioIndex === 2) {
applicationType = "upgrade";
newOrUpgrade.push(applicationType);
} else if (radioIndex === 3) {
applicationType = null;
newOrUpgrade.push(applicationType);
}
console.log("valueAppType after the function is: " + applicationType);
return applicationType;
}
console.log("application type outside the function is " + applicationType);
let options = {
contactInfo: {
"firstName": firstName,
"lastName": lastName,
"First name": firstName,
"Last name": lastName,
"Email": emails,
"dlState": state,
"dlNumber": dlNumber,
"applicationType": applicationType,
"dateOfBirth": dateOfBirth,
"tprStateCode": tprStateCode,
},
privacyStatus: 'PRIVATE'
}
console.log("Contact info was assigned" + options);
/****************************
* Page code - registration *
****************************/
// ...
authentication.register(email, password, options)
.then((registrationResult) => {
const status = registrationResult.status;
console.log("Registration status: " + status)
if (status === "PENDING") {
// When the site is configured for manual approval,
// status is "PENDING" and approvalToken is returned.
const status = registrationResult.status;
console.log('Member registered and waiting for approval:', registrationResult);
} else {
// When the site is configured for automatic approval,
// status is "ACTIVE" and the member is approved and logged in.
// To prevent logging in the member automatically,
// use the backendend function: wix-members-backend.authentication.register()
console.log('Member registered and logged in:', registrationResult);
}
wixLocation.to('domain.com/profile')
})
.catch((error) => {
console.error(error);
});
If it helps, here’s the error logs from the site preview:
The error logs from the live site follow, first the google logger and then the error from the firefox inspect window:
From what I can tell, I have two issues. The first is “i is undefined”. this might be caused by my radio buttons or maybe the email. From what I understand, the email needs to be passed as an array. However, both of these elements seem to be transferring to my contact and to the form submissions collection without any problems.
The other issue I see is “the current user does not have permission to read from the member collection”. However, I don’t see how I am trying to read from the member collection at all… is this referring to the registration promise?
My signup settings are shown below:
and here are screenshots from my contacts page:
I’ve been stuck for a while now so any help is much appreciated!!
*Edited to remove my company name from the code.