Custom Registration Form / duplicate registration

Hello,

I am facing an issue with my custom registration form. Basically when someone add his password, name, first name etc. it will created an account. But the thing is that, if he go again in the registration form and put the same email he can go on the next steps.

Here is my code :

  • Here you have the code that will create an account
import wixUsers from 'wix-users';
$w.onReady(function () {
$w('#submit').onClick( () => {
let emails = [];
let labels = [];

emails.push($w('#email').value);
// register as member using form data
wixUsers.register($w('#email').value, $w('#password').value, {
"contactInfo": {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
"emails": emails,
"labels": labels,
}
});
});
});
$w.onReady(function () {
$w('#submit2').onClick( () => {
let emails = [];
let labels = [];

emails.push($w('#email2').value);
// register as member using form data
wixUsers.register($w('#email2').value, $w('#password2').value, {
"contactInfo": {
"firstName": $w('#firstName2').value,
"lastName": $w('#lastName2').value,
"emails": emails,
"labels": labels,
}
});

});
});
  • Here is the code when we click the submit button, it will hide the registration form and make appear the next step of the form :
export function submit_click(event) {
if($w("#firstName").value && $w("#lastName").value && $w("#email").value && $w("#phone").value && $w("#password").value && $w("#checkbox46").checked && $w("#checkbox47").checked) {
$w('#creationcompte').hide();
$w('#typedecontrat').show();
}
else {
if(!$w("#firstName").value) {$w("#firstName").updateValidityIndication()}
if(!$w("#lastName").value) {$w("#lastName").updateValidityIndication()}
if(!$w("#email").value) {$w("#email").updateValidityIndication()}
if(!$w("#phone").value) {$w("#phone").updateValidityIndication()}
if(!$w("#password").value) {$w("#password").updateValidityIndication()
if(!$w("#checkbox46").checked) {$w("#checkbox46").updateValidityIndication()}
if(!$w("#checkbox47").checked) {$w("#checkbox47").updateValidityIndication()}}
}
}
export function submit2_click(event) {
if($w("#firstName2").value && $w("#lastName2").value && $w("#email2").value && $w("#phone2").value && $w("#password2").value && $w("#checkbox44").checked && $w("#checkbox45").checked)  {
$w('#creationcompte2').hide();
$w('#typedecontrat2').show();
}
else {
if(!$w("#firstName2").value) {$w("#firstName2").updateValidityIndication()}
if(!$w("#lastName2").value) {$w("#lastName2").updateValidityIndication()}
if(!$w("#email2").value) {$w("#email2").updateValidityIndication()}
if(!$w("#phone2").value) {$w("#phone2").updateValidityIndication()}
if(!$w("#password2").value) {$w("#password2").updateValidityIndication()
if(!$w("#checkbox44").checked) {$w("#checkbox44").updateValidityIndication()}
if(!$w("#checkbox45").checked) {$w("#checkbox45").updateValidityIndication()}}
}
}

If someone can help me it will be great.

try to insert your registration code in submit button code

Not working anymore, I think I made a mistake somewhere, but I add the code inside the submit button

export function submit_click(event) {
if($w("#firstName").value && $w("#lastName").value && $w("#email").value && $w("#phone").value && $w("#password").value && $w("#checkbox46").checked && $w("#checkbox47").checked)
$w('#creationcompte').hide();
$w('#typedecontrat').show();
$w.onReady(function () {
$w('#submit').onClick( () => {
let emails = [];
let labels = [];

emails.push($w('#email').value);
// register as member using form data
wixUsers.register($w('#email').value, $w('#password').value, {
"contactInfo": {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
"emails": emails,
"labels": labels,
}
});
});
});
else {
if(!$w("#firstName").value) {$w("#firstName").updateValidityIndication()}
if(!$w("#lastName").value) {$w("#lastName").updateValidityIndication()}
if(!$w("#email").value) {$w("#email").updateValidityIndication()}
if(!$w("#phone").value) {$w("#phone").updateValidityIndication()}
if(!$w("#password").value) {$w("#password").updateValidityIndication()
if(!$w("#checkbox46").checked) {$w("#checkbox46").updateValidityIndication()}
if(!$w("#checkbox47").checked) {$w("#checkbox47").updateValidityIndication()}}
}
}

Try this

$w.onReady(function () {
$w('#submit').onClick( () => {
let emails = [$w('#email').value];
let labels = [];

// register as member using form data
wixUsers.register(emails, $w('#password').value, {
"contactInfo": {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
"emails": emails,
"labels": labels,
}
});
});
});

Inside de submit button code ?

First off you should do what the forum guidelines state and search the forum before you post as you would find many previous posts that could help you here.
https://www.wix.com/corvid/forum/community-discussion/duplicate-site-members-custom-registration
https://www.wix.com/corvid/forum/community-discussion/prevent-contact-duplicates-in-custom-registration-1
https://www.wix.com/corvid/forum/community-discussion/prevent-contact-duplicates-in-custom-registration-without-costume-database
https://www.wix.com/corvid/forum/community-discussion/prevent-contact-duplicates-in-custom-registration
https://www.wix.com/corvid/forum/community-discussion/check-to-see-if-a-user-already-exists-on-signup-no-extra-db-needed

Also, have a look at Nayeli (Code Queen) own tutorial about this here which includes her YouTube video about it and the full code for you to use.
https://www.totallycodable.com/wix/corvid/register-user-to-wix-crm-and-insert-to-custom-database

Also, if you are looking at using validations, then there are many pages and examples that you can see.
https://www.wix.com/corvid/example/custom-validations
https://support.wix.com/en/article/corvid-about-validating-user-input-with-code
https://support.wix.com/en/article/working-with-user-input-validation-in-the-settings-panel
https://www.wix.com/corvid/reference/$w.ValidatableMixin.html
https://www.wix.com/corvid/reference/$w.TextInput.html