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; } ); }
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; } ); }
}
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; } ); } }) })
It's happening on the live website
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?