Insert to database (Code)

Hi there,

So I am creating a contact form on my website and I am trying to add the data to my data collection via wix code.

When I insert into the database with hard coded strings it works but when I try to insert with references to text fields this does not work? They show up blank??

My Code:

Result in Data collection:

Can someone please help me resolve this?

1 Like

Hi Scott

Your code generally speaking has all the right elements, but not necessarily in the correct order…

I would suggest that you move the ‘toInsert’ object inside the submit button’s onClick. Then, for each of your keys inside the ‘toInsert’ object, I would add the input element instead of the variable declared, for instance…:

 let toInsert = {
     "emailAddress": $w("#EmailAddress").value,
     "name": $w("#fullName").value
     }

…and so on

Tiaan

That was something that I tried but did not work? I have solved this problem since this post :slight_smile:

Hi Scott,

Please share your solution with us and edit your post title to include (Solved). For coding newbies like myself, it’s been extremely difficult to figure out how to code. I actually spend hours and hours trying to find solutions that worked for other people, then attempt to tweak their code for my own situation. It’s been a very frustrating journey because what may be simple to some people, I am completely clueless about. Im presently trying to figure out a solution to a current dilemma and I think your code could help point in my the right direction. Thank you in advance and I hope you see this (I know this post is old)

@hawaiiwedpedia I was able to get the value to submit properly by calling the .value property off the elements