Registration Forms

Hi,

I’m trying to create a custom registration form that also appends a database. In this form, I also want to do some data validation to ensure users are inputting the correct email addresses. When the user clicks the submit button, I want to send them to the home page if they have a valid email. If they input an invalid email, I want to send them to the about page. I’m having trouble as the submit button will still bring you to the home page even if the data validation requirements aren’t met. I’ve copy and pasted the code I’m working with below. Any help is greatly appreciated, whether you can fix my code or come up with a better way to do it! Thanks!

$w(‘#button7’).onClick( function (){
let y = $w(‘#email’).value;
if (y.endsWith(‘@wix.com’)=== true ) {
wixData.insert(“Registration”, {“email”: $w(‘#email’).value},
{“Name”: $w(“#input6”).value},
{“birthdate”: $w(“#input2”).value});
let email = $w(‘#email’).value;
let password = $w(‘#password’).value;
wixUsers.register(email,password);
wixLocation.to(‘/Home’); }
else {wixLocation.to(‘/about’)}}

You can see a fully setup Wix Editor tutorial here about custom validations on email addresses.
https://www.wix.com/corvid/example/custom-validations

For info about validations see here.
https://support.wix.com/en/article/corvid-about-validating-user-input-with-code
https://www.wix.com/corvid/reference/$w.TextInput.html
https://www.wix.com/corvid/reference/$w.TextInput.html#onCustomValidation
https://www.wix.com/corvid/reference/$w.ValidatableMixin.html

Have a look at register and insert api reference too.
https://www.wix.com/corvid/reference/wix-users.html#register
https://www.wix.com/corvid/reference/wix-data.html#insert

Finally, have a look at the code from Wix custom code member profile page as it shows you how to apply some of the code that you are wishing to implement in your own site.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

1 Like

Hi, thank you for the help! The only problem I’m having now is getting the input fields to sync with the database. I’ve read through those links, but just can’t find the error in my code. When I click the button it will register the user, but it will not send the data (email and name) to the database I’ve set up. The link to my site is collegetownconnect.com Thanks again for all your help!

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import wixData from ‘wix-data’;
export function button7_click(event) {
let y=$w(‘#email’).value
let z=$w(‘#password’).value
if (y.endsWith(‘@wix.com’)) {
wixData.insert(“Registration”, {“email”: $w(‘#email’).value},
{“Name”: $w(“#input6”).value});
let email = $w(‘#email’).value;
let password = $w(‘#password’).value;
wixUsers.register(email,password)
.then()
wixLocation.to(‘https://www.collegetownconnect.com’)
} else {
$w(‘#text26’).show()
}
}

Have a read of Steve’s reply to this previous forum post that is similar to yours as it should give you a good starting point to work off of.
https://www.wix.com/corvid/forum/community-discussion/how-to-create-database-entries-when-a-user-sign-up

1 Like