Required fields before submission

Hi,
I’m not a code expert, but I managed to create a custom registration form, and it works perfectly.
The problem is that Wix is not preventing users to submit the form with the “required” fields like First Name and Last Name being blank.

So I would get a new member notification with no names provided :frowning:

Can someone help me restrict Wix from accepting a member without filling the required fields?

Here’s the code I’m using. I dunno where and what to write in order to achieve this.
I tried the OnBeforeSave function from this article , but, being the beginner I am, I can’t get it to work.

Here’s the code that I used for the custom registration:


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

console.log('Hello'); 

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

let email = $w(‘#email’).value;
let password = $w(‘#password’).value;
console.log(email + ’ ’ + password);
wixUsers.register(email, password)

});
});


And here’s the form URL: https://www.arapd.org/register-member

Somebody help please :frowning:

First of all, you can set NY field to be "required’ via the editor, and no code is needed.
Second, if you choose to make it by code, you can do a validation by yourself:

  $w("#firstNameInput, #lastNameInput").onBlur(( event) => { 
if($w("#firstNameInput").value.length  > 0 && $w("#lastNameInput").value.length  > 0) {
  $w("#submitButton").enable();
} else {
 $w("#submitButton").disable() 
}
}); 

Thanks J.D. in fact I have those fields as “required” in the settings. Even though, the user can still press Submit without filling them, and I would get get a member notification without those fields filled.

@aghassan it’s not supposed to behave like that. Are you sure you remembered to connect the input fields to the database fields ?

Yes all of them are connected to database

So, I don’t know what to say. Maybe you should talk to the support.

I’ve run into the same problem with yesoil.biz. I was hoping to resolve it. The input fields are set to required. I was testing it and had no problem submitting the registration without the last name field.

And the code sample for the validation doesn’t work either. This is really frustrating.

Is this problem fixed?

Nope. I’ve tried the custom sign-up and log in forms, can’t customize the log in form to match the sign-up form and the website style (which is very simple, gray-scale colors). I was told by support that the “custom” log in form can’t be customized. I’ve tried 3-4 different ways to code it. The onBlur((event)) doesn’t work at all - event is grayed out. I also tried a form and a lightbox. We no longer have the option of a Password type which I used for a sign-up/log in system on another client’s website a couple years ago. That one still works but the system won’t let me duplicate it. I’ve been working on this off and on for days. It looks like the only solution might be the ugly default forms. That’s not what my client is paying for.

I am running into the same issue. Is there any update out there?

I finally got my registration and login forms to work by creating lightboxes. Miraculously, the password field type has been restored to the system!!

I’m waiting for a fix on the promptForgotPassword() function for the mobile version of the login box. It works on the desktop version. But given that we’re this far, I’m comfortable that this will work.

Here’s the code for my Registration form -

import wixUsers from ‘wix-users’ ;
import wixLocation from ‘wix-location’ ;
import wixWindow from ‘wix-window’ ;

$w . onReady ( function (){
$w ( ‘#registerNow’ ). onClick ( function (){
if (( $w ( ‘#regFirstName’ ). value === “” )||( $w ( ‘#regLastName’ ). value === “” )) {
$w ( “#noBlankFields” ). expand ()
} else {
let email = $w ( ‘#regEmail’ ). value ;
let password = $w ( ‘#regPassword’ ). value ;
let first = $w ( ‘#regFirstName’ ). value ;
let last = $w ( ‘#regLastName’ ). value ;
let fullname = $w ( ‘#regFirstName’ ). value + " " + $w ( ‘#regLastName’ ). value ;

    wixUsers . register ( email ,  password ,{  
   contactInfo : {  

“firstName” : first ,
“lastName” : last ,
//“name”: fullname
}
} )
. then (()=>{
wixWindow . lightbox . close ();

wixWindow . openLightbox ( “YESSignIn” );

})
. catch ( ( err ) => {
console . log ( err );
$w ( “#dupRegistration” ). expand ();
} );
}
});

$w ( “#signin” ). onClick (( event )=> {
wixWindow . openLightbox ( “YESSignIn” );
})

});

Good luck!!