SOLVED! Unable to save data on a database

Hi there!

I’m having trouble saving to a dataset from another dataset and i just couldn’t figure it out


←#username: is the data i’m calling from droptest database
←#userinput: is a required!! form element for creating data on MemGenDrops database.

I can get the value from #username to #userinput successfully with a checkbox trigger but the submit button is not saving the value on userinput1 and It comes out empty on the database. even tried putting [1]{3,15}$ validation still getting no result.

droptest is the database where i collect member information and i set it to the state where they can create their #username only once.

MemGenDrops is the database where members share their links. written on the members profile area and viewed by public on the main site. (/yourdrops)

Q1
So the permissions are set correctly, though it wouldn’t create the data otherwise but i’m missing this username part and i can’t figure out what’s wrong with this setup.

Q2 (Related question but not exactly about the main problem here)
How can i create a unique data for #username? I checked the hooks section but it’s some random characters come together for me :slight_smile: Can’t understand it. Could anyone possibly show a working example here?

My main problem here is that i can’t show that #username data even if it’s unique or not. I have to complete this in order to show members how many links they have shared etc. on their profile pages and also to show the usernames on the main page. I set up a search for it already so i need that data :slight_smile:

Thank you.

www.z365air.com
/droptest/{ID}


  1. a-zA-Z0-9_ ↩︎

To be more clear
http://www.screencast.com/t/9HSvIMNpH

Hi,

to safely set and safe the values of components that are bound to data set, it is best to use setFieldValue(…) on the dataset.

$w('#dataset1').setFieldValue('fieldKeyAsInDatabase', value)

You can read more about it here:

$w(’ #dataset1 ').setFieldValue(‘fieldKeyAsInDatabase’, value) ?
How can i adapt this to a form
I just didn’t understand the relation between setFieldValue() and getting data from database-A and puting it on a userinput which creates a new data on database-B
Can you please be a bit more clear for me to understand.

Please don’t get me wrong though i really have no idea what i am doing with all these codes :slight_smile: i just try around the things i find useful and they just happen like a magic “for me at least” :slight_smile: That until now… i’m really stuck here. It’s just not accepting that value because it’s generated not put.

In your case replace value with the actual value like $w(‘#username’).value .

What this method does, is updates the current item of the dataset (the one being edited) and makes sure that all bound components are updated. It will update current item, even if there are no bound items.

If you need unique id of the user, you can use wix-users API. It will give you your user site member id. It uniquely identifies the user of your site.

const uniqueUserId = wixUsers.currentUser.Id

See here for more details:
https://www.wix.com/code/reference/wix-users.html#currentUser

You can also click on [Visible Fields] in Content Manager and check the Owner field. It contains the site member ID that inserted the into the database (the same you would get using the API).


Thank you!!