chajj
January 15, 2019, 8:14pm
1
Hello!
Hope someone can guide me on how to solve this. I have a form that submits into a database through code. When the user clicks Submit, the code works and it submits to the database successfully. However, it submits twice. As if the user clicked twice on the Submit button (when they’ve clicked once).
I have created forms through code multiple times but this is the first time this has happened. I was wondering what may be the cause and how to resolve it.
Thank you!
import wixData from ‘wix-data’;
export function button71_click(event) {
console.log(“Clicked”);
let toInsert = {
“referralNetwork”: true ,
“firstName”: $w(‘#firstName ’).value,
“lastName”: $w(‘#lastName ’).value,
“email”: $w(‘#email ’).value,
“companyName”: $w(‘#company ’).value,
}
wixData.insert(“SiteMembers”, toInsert)
.then( (results) => {
let item = results;
$w(‘#text337 ’).show();
SendClientEmail();
wixLocation.to(“/account/my-account”)
} )
. catch ( (err) => {
$w(‘#text338 ’).show();
let errorMsg = err;
} );
}
chajj
January 15, 2019, 8:19pm
2
This is a screenshot of the Live Database. You can notice in the Created Data how both submissions were made at the same time.
I found this article on the forum
https://www.wix.com/code/home/forum/wix-tips-and-updates/we-re-getting-faster-learn-how-to-get-your-site-ready
Would that be related?
this happens in wix preview mode I believe due to pre-rendering I think.
is it happening on your live site ?
chajj
January 15, 2019, 8:39pm
4
It’s happening on the live website
try this…
import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;
import wixLocation from ‘wix-location’;
//import your backend email function here too
$w.onReady( function () {
$w('#button71').onClick( **function** () {
console.log(“Clicked”);
let toInsert = {
“referralNetwork”: true ,
“firstName”: $w(‘#firstName ’).value,
“lastName”: $w(‘#lastName ’).value,
“email”: $w(‘#email ’).value,
“companyName”: $w(‘#company ’).value,
}
if (wixWindow.rendering.renderCycle === 1) {
wixData.insert(“SiteMembers”, toInsert)
.then( (results) => {
let item = results;
$w(‘#text337 ’).show();
SendClientEmail();
wixLocation.to(“/account/my-account”)
} )
. catch ( (err) => {
$w(‘#text338 ’).show();
let errorMsg = err;
} );
}
})
})
chajj
January 15, 2019, 9:13pm
6
Hi Mike,
It stopped submitting completely.
export function button71_click(event) {
console.log(“Clicked”);
let toInsert = {
“referralNetwork”: true ,
“firstName”: $w(‘#firstName ’).value,
“lastName”: $w(‘#lastName ’).value,
“email”: $w(‘#email ’).value,
}
if (wixWindow.rendering.renderCycle === 1) {
wixData.insert(“SiteMembers”, toInsert)
.then( (results) => {
let item = results;
$w(‘#text337 ’).show();
SendClientEmail();
wixLocation.to(“/account/my-account”)
} )
. catch ( (err) => {
$w(‘#text338 ’).show();
let errorMsg = err;
} );
}
}
i wouldn’t be supersized, try copying the above code correctly
chajj
January 17, 2019, 8:11pm
8
Sorry didn’t notice that you placed it in the onReady function. I copied the code exactly as is but it still didn’t submit at all.