i created a dataset and a form to updtae the collection
on the form i have input fields that i want to use as a member sign-up
the update to the custom collection i attach to works fine
on the submit button i include this code to register the visitor as a member… but it des not create a member or a contact?
import wixUsers from ‘wix-users’;
$w.onReady( function () {
let email = $w(‘#Email’)
let password = $w(‘#PWORD’)
let firstName = $w(‘#FirstName’) // the user’s first name
let lastName = $w(‘#Surname’)
let phone = $w(‘#Primaryphone’)
let otherphone = $w(‘#otherphone’)
function join_click(event) {
//Add your code for this event here:
wixUsers.register($w(‘#Email’).value, $w(‘#PWORD’).value,{
contactInfo: {
“firstName”: firstName,
“lastName”: lastName,
“phone”: phone
}
} )
.then( (result) => {
let resultStatus = result.status;
})
}
});
try this…
$w(‘#join’).onClick( function () {
wixUsers.register(email, password, {
“contactInfo”: {
“firstName”: firstName,
“lastName”: lastName
“phone”: phone
}
})
})
same problem
contacts updated but no entry in members set
Try changing the password your using to register
Hi bobmitchy,
Maybe you can try the following code and let us know what the log messages say in the Developer tools’ Console:
wixUsers.register(email, password, {
"contactInfo": {
"firstName": firstName,
"lastName": lastName,
"phone": phone
}
})
.then( (results) => {
if(results !== null && results !== undefined){
console.log("STATUS - "+results.status);
if(results.user !== null && results.user !== undefined){
console.log("USER ID - "+results.user.id);
results.user.getEmail()
.then( (email) => {
console.log("EMAIL - "+email);
});
}
}
});
Best,
Nick
I am using this code to validate any errors on my form and also insert the customer data into my dataset. Everything works, the contact is created and can log in. However, neither the data is going in my dataset nor the wixlocation-to works to redirect customer after registration. Can someone help please what am I doing wrong ?
import wixUsers from ‘wix-users’ ;
import wixLocation from ‘wix-location’ ;
import wixWindow from ‘wix-window’ ;
import wixData from ‘wix-data’ ;
let registration;
$w.onReady( function () {
$w( “#registrationButton” ).disable();
$w( ‘#errorMessage’ ).hide(); //We want to hide all error messages when the person attempts to register again
$w( ‘#emailExists’ ).hide(); //We want to hide all error messages when the person attempts to register again
$w( “#termsBox” ).onChange((event) => {
let isChecked = $w( “#termsBox” ).checked; //This will return result of True or False
if (isChecked) {
$w( “#registrationButton” ).enable();
} else {
$w( “#registrationButton” ).disable();
}
});
if (wixUsers.currentUser.loggedIn) {
wixLocation.to( “/account/my-account” ); //Change the URL ending to the page you want to redirect the user if they are already logged in
}
$w( “#registrationButton” ).onClick((event) => {
console.log( “Button was clicked” ); //You can change the text of this line or delete it
$w( ‘#errorMessage’ ).hide(); //We want to hide all error messages when the person attempts to register again
$w( ‘#emailExists’ ).hide(); //We want to hide all error messages when the person attempts to register again
if ($w( “#email” ).valid && $w( “#password” ).valid && $w( “#firstName” ).valid && $w( “#lastName” ).valid && $w( “#stateresidence” ).valid && $w( “#cityresidence” ).valid) {
let email = $w( “#email” ).value;
let password = $w( “#password” ).value;
let first = $w( “#firstName” ).value;
let last = $w( “#lastName” ).value;
let state = $w( “#stateresidence” ).value;
let city = $w( “#cityresidence” ).value;
wixUsers.register(email, password, {
contactInfo: {
“firstName” : first,
“lastName” : last
}
})
.then((result) => {
$w( “#Memberdataset” ).save()
.then((item) => {
wixLocation.to( “/account/my-account” ); //Change the URL ending to the page you want to redirect the user after they successfully register
})
. catch ((err) => {
let errMsg = err;
});
})
. catch ((err) => {
let errorMsg = err;
console.log(err);
$w( ‘#emailExists’ ).show(); //This is were we prompt the message to show up again ONLY if there is an error
});
console.log( “Trying to register” ); //You can change the text of this line or delete it
} else {
$w( ‘#errorMessage’ ).show(); //This is were we prompt the message to show up again ONLY if there is an error
console.log( “Missing information” ); //You can change the text of this line or delete it
}
});
});
Hello photography…
…nor the wixlocation-to works to redirect customer after registration
just tested a part of you code…
function xxx () {
if (wixUsers.currentUser.loggedIn) {console.log(wixUsers.currentUser.loggedIn)
wixLocation.to("/account/my-account"); //Change the URL ending to the page you want to redirect the user if they are already logged in
}
}
…works without any problems.
Perhaps this can help you a little bit more…
https://russian-dima.wixsite.com/meinewebsite
- Check also DATABASE-PERMISSIONS
- READ-WRITE-PERMISSIONS on DATASET
I did not looked at all parts of your code!
Database permissions are set to write
Thanks for trying out my tutorial!
So the reason your Location redirect does not work during the registration part of your code is because it is only triggered after your dataset is saved. So …if your dataset does not save …then the location redirect will not be triggered.
The problem could be any number of factors besides your actual code. (When posting questions, it is best to post with screenshots.) For example …
Are all your inputs connected to the dataset?
Are the database permissions correct?
Are all required fields valid and not empty?
Is the database ID correct?
Is dataset set to write only?
Etc.
Hello Code Queen,
Thanks a ton for the insight. I think now it made sense and I created a new collection and redesigned the flow to check if the problem was with my collection. You know what yes that was the case. I am now able to push the data and also redirect user to a Thank You Page.
I have couple more questions if you could please answer or direct me in the right direction ?
-
How can I redirect user to a lightbox instead of a page in the same code above from your tutorial ?
-
Is there a way to build a referral program in wix ?
-
How to assign badges to my members based on their activities. I want to build a loyalty program for my website of community members, where each member will earn points based on referrals, no. of forum posts, comments, shares, likes etc.
Any help is much appreciated. Thanks again!!
@code-queen - I am also using this code to Register a user and send email confirmation for verification. However, when I use the registration page piece under the code provided by you, my signup button always remains disabled. Can you please help in what should be changed ?I am also getting below
error
A button only becomes disabled when the dataset permissions are incorrect (read only or read & write instead of write-only). If you are using a button to trigger a custom code ---- it most likely should host be connected to anything at all.
It looks like you are pasting code directly from the Wix Reference guide. They are simple sample codes that are incomplete. It is up to you to complete them and place them in the right place if appending to existing code on your page.
Your screenshot shows this:
let password = //something something something;
After you complete the code with something like this:
let password= $w("#theNameofYourElement").value;
Your errors should disappear.
These lines:
//
are used to comment or add notes at the end of your codes lines. They are not actual code that is being considered.
(I forgot to hit publish)
Yes, you can modify the code as needed. Here is documention on opening and closing lightboxes:
https://www.wix.com/corvid/reference/wix-window/openlightbox
https://www.wix.com/corvid/reference/wix-window/lightbox/close
I also have very old tutorial about opening lightboxes: https://www.totallycodable.com/post/open-a-lightbox-or-show-and-hide-a-hidden-element-using-corvid
To answer you referral question: there is no native app that will offer this functionality. Other apps (such as Ecwid ) have this functionality available with add-on premium apps. If you want something like this on Wix you can either embed a store app that offer this or code something custom. You may or may not be able to create something with Wix Stores app. It really all depends on the flow and functions you decide you need and want. Not everything in the Wix Stores app is codable so ----- you will have to get really creative and plan something (aka Project Planning) with an advanced coder to attempt to tackle each of your goals. (Has these been created on Wix before? I’m sure of it (by using other store apps). Has this ever been coded? I’m not sure. There is a first time for everything. None of my clients have chosen custom-build vs something that is ready ‘out of the box’, due to time and cost.
To answer your ‘assign a badge’ question. The Wix Forum app is also limited in coding. There are no API codes for us to detect real-time events from the Forum app. But yes, you can query any data that is collected or visible within your editor. In other words, if the Wix Forum database shows the number of comments, then you can do something with that number. If it shows the number of shares, then you can do something with that number. If it does not, then no, it cannot be coded. The complexity of the code will be determined by the logic you want to use to trigger that query. (Like … will it be triggered each day that one person logs in? <— that would be less complex because you run the code as needed for 1 individual person. Or will the code be triggered for all person once every ____. <— that would more complex because the code would have to be looped around and continuously run for every single person.)
To learn what data is saved in the Forum app database, simply open it up in your editor and then browse through the fields / columns it has.
Thank You so much @code-queen . My errors are resolved now but the functionality is still not working. HAHA
I have a call setup with you next tuesday, we can discuss then. But again thanks a lot!