Custom registration query

Hi
I followed the tutorial - Velo Tutorial: Creating a Custom Registration Form with Code | Help Center | Wix.com and I see that even though First and last name is marked compulsory, if left blank, the code to register will still execute.
Am I doing something wrong or is just email and password the only requirements for register a member and the rest just optional?

My own custom register lightbox works fine

This works perfectly and closes after registering details before moving the user onto the sign up status page, then both names will be saved in contacts and once site member is approved the member details will be added to ‘members’ database.

I’ve just made sure that the email, password, first name and last name user inputs are all set to required in their settings in the Wix Editor as only email and password is actually needed by Wix to complete user registration.

Otherwise you can always add extra code that checks the user inputs are not left empty and then shows an error message like ‘name is required’ if not filled in.

import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';

$w.onReady(function () {
    
    $w("#registerButton").onClick( (event) => {
        
   let email = $w("#email").value;
   let password = $w("#password").value;
   let first = $w("#firstName").value;
   let last = $w("#lastName").value;

   wixUsers.register(email, password, {
       contactInfo: {
        "firstName": $w('#firstName').value,
        "lastName": $w('#lastName').value,
       }
      } )
      .then( (result) => {
        let resultStatus = result.status;
  wixWindow.lightbox.close();
  wixLocation.to("/sign-in-status");  //Change the URL ending to whatever page you want to send the user to after they log in.
      } );     
    } );
    
});

Thank you for replying.
Below is my code. I made sure that all the inputs are set to required. I’m not using the wix window api in mine. I see you mentioned a “members database” I was under the impression that this code will write straight to the wix CRM?
Just to reiterate, my problem is that if i leave firstname and lastname blank and even though they are marked as required, the code executes.

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
// …
$w.onReady( function (){

$w('#registerButton1').onClick( **function**  (){ 

let email = $w(‘#email’).value;
let password = $w(‘#password’).value;
let firstName = $w(‘#firstName’).value;
let lastName = $w(‘#lastName’).value;

wixUsers.register(email, password, {

contactInfo: {
“firstName”: firstName,
“lastName”: lastName,

}
} )

.then(()=>{

        wixLocation.to('/my-page');  

} )
. catch ( (err) => {
console.log(“err”);
$w(“#errorMessage”).expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to ‘collapse on load’ from the Properties Panel.
} );
})

})

export function agree_change(event) {
if ($w(‘#agree’).checked) {
$w(‘#registerButton1’).enable();
} else {
$w(‘#registerButton1’).disable();
}
}

I think I see the issue

@givemeawhisky - Hi, I used your code and tested and it still registers a member even if email and password is only entered. Its weird that this code works for you and not me.

I mentioned a Members database as I had created a members profile area, similar to the example here:

However, all the details will still be saved in the Wix CRM first and shown in the contact list, only after the member is approved will their details get added to my members dataset as well.

Also, make sure that you test your register/login on your published website and not just on the preview only, as the APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

As for your code itself, it seems that you’ve taken bits and pieces from that tutorial, so I suggest you change the following in your code:

Change yours from this:

$w.onReady(function () {

$w('#registerButton1').onClick(function (){

let email = $w('#email').value; 
let password = $w('#password').value; 
let firstName = $w('#firstName').value; 
let lastName = $w('#lastName').value;

wixUsers.register(email, password, {
contactInfo: {
"firstName": firstName,
"lastName": lastName,

Change it to this:

$w.onReady(function () {

$w("#registerButton1").onClick( (event) => {

let email = $w("#email").value;
let password = $w("#password").value;
let first = $w("#firstName").value;
let last = $w("#lastName").value;

wixUsers.register(email, password, {
contactInfo: {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,

//You already have the function in with the onReady, don't need it in the click event on next line too.


.
Change yours from this:

.then(()=>{
wixLocation.to('/my-page');  

Change it to this:

import wixWindow from 'wix-window';
//add the import to the top underneath the other imports

.then( (result) => {
let resultStatus = result.status;
wixWindow.lightbox.close();
wixLocation.to("/my-page");



Add in again below the WixLocation.to, your code parts for error catching and the export function for the agree checkbox, obviously making sure that there are now not any errors in the code with any extra {} or () now that we have modified your code.
   
} )
.catch( (err) => {
console.log("err");
$w("#errorMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel.
} ); 
})
})

export function agree_change(event) {
if ($w('#agree').checked) {
$w('#registerButton1').enable();
} else {
$w('#registerButton1').disable();
}
}

You need the wix Window as you are using a lightbox for your custom sign up and login, otherwise you are not telling your lightbox to close before moving onto your ‘my-page’

I would test it again from your website after you saved and published it all and not by testing it just through the preview mode only.

The other option you have if the required settings for first and last name are not working for you, is to add code to check whether the user has filled in those fields so they are not left blank.

@givemeawhisky
Hi, I used your code. I also made sure to publish the site and test and still no joy.
I am a novice coding and appreciate all the help I can get. I want to try the next option which will be code to check that those fields are not blank and if blank, not to register the use.
Can you please help me with that bit of code?

@givemeawhisky
I found this tutorial for custom registration - https://support.totallycodable.com/en/article/custom-registration-for-site-login
It has a live example as well - www.totallyshoppable.com
I see that here as well, if I leave out first and last name, it still registered me. Just weird. Starting to wonder if its not me and a wix issue