Hi!
Need some help with the redirect function.
I've created a sign up lightbox with custom fields using wix members sign up custom form.
I've set most of the fields as required. So far everything works perfectly. When the user hit the sign up button all data from the form is stored in the site members dashboard.
Then I added code (found here on the forum) that redirects the user after pushing the submit button to another page on my site.
This also works fine.
The problem is that after adding the code the required fields on the form is no longer active. The user only has to fill in the email and password fields to be able to sign up.
That means I might not get all the info I want/need from the users.
What I'm I doing wrong. Do I have to add something in the code or is it just in the wrong place?
Here's the code:
import wixUsers from 'wix-users';
import wixLocation from "wix-location";
$w.onReady(function () {
$w('#button34').onClick(() => {
let email = $w('#input3').value
let password = $w('#input4').value
let firstName = $w('#input1').value
let lastName = $w('#input2').value
let phone = $w('#input5').value
let street = $w('#input6').value
let zip = $w('#input7').value
let city = $w('#input8').value
let country = $w('#input9').value
let choir = $w('#dropdown1').value
let checkbox1 = $w('#checkbox1').value
wixUsers.register(email, password,
{
contactInfo: {
"firstName": firstName,
"lastName": lastName,
"phone": phone
}
} )
.then( (result) => {
let resultStatus =
result.status;
wixLocation.to('https://www.google.se');
} );
});
});
Thanks in advance / Kristoffer
You are not checking if the entries are valid (filled) or not. You need to run a check for them like below.
import wixUsers from 'wix-users'; import wixLocation from "wix-location"; $w.onReady(function () { $w('#button34').onClick(() => { validateEntries(); }); }); function validateEntries() { let formFields = ['input3', 'input4', 'input1', 'input2', 'input5', 'input6', 'input7', 'input8', 'input9', 'dropdown1', 'checkbox1']; if(formFields.every(input => $w(`#${input}`).valid)) { registerAndRedirect(); } else { //show an error here } } function registerAndRedirect() { let email = $w('#input3').value; let password = $w('#input4').value; let firstName = $w('#input1').value; let lastName = $w('#input2').value; let phone = $w('#input5').value; let street = $w('#input6').value; let zip = $w('#input7').value; let city = $w('#input8').value; let country = $w('#input9').value; let choir = $w('#dropdown1').value; let checkbox1 = $w('#checkbox1').value; wixUsers.register(email, password, { contactInfo: { "firstName": firstName, "lastName": lastName, "phone": phone } }) .then( (result) => { let resultStatus = result.status; wixLocation.to('https://www.google.se'); }) .catch( (err) => { //show an error here }); }
CorvidCommunity ROCKS!
Please can you mark Shan's reply with best answer as you seem to be happy with it. 😉
It will help others find it easier if they run into the same or similar issue, thanks.
Following on from Shan's great reply above, also note that Nayeli (Code Queen) has recently released a tutorial and youtube video on this which you might want to check out too. https://www.totallycodable.com/wix/corvid/corvid-registration-code-check-existing-user-and-input-validation
Wix Custom Registration to Check Existing User and Input Validation - youtube video
For more on validation, you can check Wix Support pages about it here.
https://www.wix.com/corvid/example/custom-validations
https://support.wix.com/en/article/corvid-about-validating-user-input-with-code
https://support.wix.com/en/article/working-with-user-input-validation-in-the-settings-panel
https://www.wix.com/corvid/reference/$w.ValidatableMixin.html