Adding Signup Information to Accessable Database

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.

Hello again :grin:.

Perhaps you take a look onto this post here…
It could help you understanding some code-parts better…

https://www.wix.com/velo/forum/community-discussion/multistep-form-connection-to-a-database-except-contacts

Your “let toSave” is not correct defined…

wrong-way

let toSave = {
 // Saves Email (input2), First Name (input 4), Last Name (input 3), Year (dropdown1)
 "title": #input2,
 "firstname": #input4,
 "lastname": #input3,
 "year": #dropdown1
                };

right possible way-1 (comments should also be placed RIGHT!)

// Saves Email (input2), First Name (input4), Last Name (input3), Year (dropdown1)
let toSave = {
    "title":     $w('#input2').value,
    "firstname": $w('#input4').value,
    "lastname":  $w('#input3').value,
    "year":      $w('#dropdown1').value,
};

right possible way-2

// Saves Email (input2), First Name (input4), Last Name (input3), Year (dropdown1)
let TITLE = $w('#input2').value
let firstNAME = $w('#input4').value
let lastNAME = $w('#input3').value
let YEAR = $w('#dropdown1').value

let toSave = {
    "title":     TITLE,
    "firstname": firstNAME,
    "lastname":  lastNAME,
    "year":      YEAR,
};

I did not look on all your other code, just saw this part of code.

Thank you so much for the help that you have continually given me but in saying so I am once again in need of your expertise.

I have rectified my code as per your reply and have temporarily changed my database’s permissions so anyone can read, create and update my collection.

I no longer get the error but when I run it, two blank items are added to my database. I’ve successfully tried just adding a string to a field in the database and changing a text box to the value of #input2 through a button press.

The value of the input field can only be submitted if it is filled so I am unsure as to what is causing this.

Any assistance in explaining or solving this issue would be greatly appreciated.
Thank you, again.

@brodietaylor2004
You should ALWAYS show your current updated CODE!
I can’t see the CHANGES, which you have already done to your CODE.

And what i can suggest you —> is to work more with CONSOLE.

For example…
…after generating a query and some filtering processes…

wixData.query("members")
  .eq("title", #input2)
  .find()
  .then( (results) => {console.log(results.items)})

…you will be able to see the current results in the console. This will give you a better overview about your CODE and its results and working way.

The more you will use the CONSOLE, the better you will understand your own CODE!

You want to generate this…

// Saves Email (input2), First Name (input4), Last Name (input3), Year (dropdown1)
let TITLE = $w('#input2').value
let firstNAME = $w('#input4').value
let lastNAME = $w('#input3').value
let YEAR = $w('#dropdown1').value

let toSave = {
    "title":     TITLE,
    "firstname": firstNAME,
    "lastname":  lastNAME,
    "year":      YEAR,
};

Then also add some console logs…like this…

// Saves Email (input2), First Name (input4), Last Name (input3), Year (dropdown1)
let TITLE = $w('#input2').value
let firstNAME = $w('#input4').value
let lastNAME = $w('#input3').value
let YEAR = $w('#dropdown1').value

console.log("TITLE = ", TITLE)
console.log("First-Name = ", firstNAME)
console.log("Last-Name = ", lastNAME)
console.log("YEAR = ", YEAR)

let toSave = {
    "title":     TITLE,
    "firstname": firstNAME,
    "lastname":  lastNAME,
    "year":      YEAR,
};

In this way of coding you will always understand your CODE and you will always see the current processes, made by your written CODE.:wink:

Press F-12 in Google-Chrome, go to CONSOLE and see your RESULTS.

@russian-dima

Thank you so much for helping.
With your assistance, I have finally achieved my desired outcome.
I commend you on your consistent professionalism and kindness.
All the best, you will no doubt end up seeing me again.

@brodietaylor2004
You are welcome. :wink: