Hello everyone! I've run into a strange problem that I'm not sure how to solve. Apologies if I've made any obvious mistakes, but I'm quite new to Wix Code!
I've created a form on one of my pages, with a submit button at the bottom. On clicking this button, I'd like the user ID to be recorded along with all the other data, by using the OnClick event for the submit button (button_1). The value of input1 is recorded correctly, but it seems the userID field keeps getting recorded during the very short time that the user is clicking on the button:
![](https://static.wixstatic.com/media/a27d24_deaab820bb0244079af6482c135b667f~mv2.png/v1/fill/w_980,h_551,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/a27d24_deaab820bb0244079af6482c135b667f~mv2.png)
As you can see, multiple entries of the same user ID are created at 00:25, whereas I would ideally only want one. This is my code:
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
//TODO: write your page related code here...
});
export function button1_click(event) {
//Add your code for this event here:
let userId = wixUsers.currentUser.id;
let NewOrder = {
"Title": $w("#input1").value,
};
wixData.insert("Orders", NewOrder)
("Orders").setFieldValue('userid',userId);
}
Hard to tell. The reason @Yisrael (Wix) mentioned could be one source. Another known source of this problem is if you register the onClick() event handler in code, and that code gets repeated with every new submission of data. But that one should increment with every submission, so click, save once, click again, twice, click again, thrice, etc.
Show us the code, we can help you better.
Is #button1 also "connected to" Submit?
If you have Submit, then the Submit dataset action performs a dataset save and your onClick() event handler also saves. So, you have two saves.