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’)}}
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()
}
}