Custom Registration Code

Hi there!

I have a custom registration page that I need help. I have First Name, Last Name, Email, and Password. I would like to require the First name, Email and password. I checked the required checkbox on the settings for the three. However, I tried it on the live website and it still let me register even without my first name.

Also, I have an error message I would love to show when a required field is missing/error. Is that on the correct line?

Additionally, the code works fine before but it won’t work just now . It seems Wix has problems with these code sometimes. It won’t register anymore. Please help!

My code is below:

  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": first,
"lastName": last,
}
} )
.then(()=>{
wixLocation.to('/home'); 
})
.catch( (err) => {
$w("#error").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.
} );
})
}) 
  

Make sure that you copy other codes properly so that they work correctly.

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.
      } );     
    } );
    
});

@givemeawhisky How do I display an error message like the one on my code? When I tried submitting without an input, the boxes never turn to red to prompt that it is required. Also, my error message won’t pop up since it is not in the code. Can you help me, please? I tried inserting the .catch code to your code but I don’t know where.