I am relatively new to Wix, Velo, and Javascript and am wanting to add information from a signup form to a database that I can alter and, that my members can submit to and modify.
I have written the following code from snippets I have found throughout Velo Reference. I cannot seem to find a way to ‘Connect to Data’ and am struggling to find what I should exactly put in the code to read the input fields ( #input_ seemed to work for custom validation so I started with that)
#input2 , #dropdown1 , etc are labeled with a parsing error ‘#’, while input2, dropdown1, etc are labeled as undefined.
import wixData from 'wix-data';
$w.onReady(function () {
// input 2 is an input that contains email
$w("#input2").onCustomValidation( (value, reject) => {
if( !value.endsWith("@gmail.com") ) {
reject("Email address must be a Google address.");
}
else {
$w('#registrationForm1').onWixFormSubmitted((event) => {
wixData.query("members")
.eq("title", #input2)
.find()
.then( (results) => {
if(results.items.length > 0) { //If email is in database do nothing
let firstItem = results.items[0]; //Unsure what this is, was in a tutorial I found & doesn't seem to be causing harm
} else { //If is not in database...
let toSave = {
// Saves Email (input2), First Name (input 4), Last Name (input 3), Year (dropdown1)
"title": #input2,
"firstname": #input4,
"lastname": #input3,
"year": #dropdown1
};
wixData.save("members", toSave)
.then( (results) => {
let item = results;
} )
.catch( (err) => {
let errorMsg = err;
} );
}
} )
.catch( (err) => {
let errorMsg = err;
} );
});
}
} );
});
export function registrationForm1_wixFormSubmitted() {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
}
I am not sure how to use this final function, it appeared on its own but, to my knowledge, doesn’t impact my code.
The database has permissions set to "Member-Generated Content.
Any help toward saving this information would be greatly appreciated, even if the method strays completely from the direction I have taken.
Thank you in advance.