Form submission also creating blank entry in database

Hi,

I have a member signup form which is all working fine but as well as creating an entry in the database with the new member information, a blank entry is also created. Can anyone help me as to why this is?

My submit button code is as follows…

export function btnSubmit_click(event, $w) {

 let toSave = {
 "firstName": $w('#inputFirstName').value,
 "lastName": $w('#inputLastName').value,
 "jobTitle": $w('#ddJobTitle').value,
 "company": $w('#inputCompany').value,
 "email": $w('#inputEmail').value,
 "accepted": $w('#cbAgreeToTerms').checked,
 "approved": "0"
 };

 let validationMessage = '';

 if (!($w('#inputFirstName').valid && $w('#inputLastName').valid &&         $w('#inputCompany').valid &&
            $w('#inputEmail').valid && $w('#ddJobTitle').valid && $w('#cbAgreeToTerms').checked)) {

 if (!$w('#inputFirstName').valid || !$w('#inputLastName').valid)
            validationMessage += 'Please enter your name\n';

 if (!$w('#ddJobTitle').valid)
            validationMessage += 'Please select a job title\n';

 if (!$w('#inputEmail').valid)
            validationMessage += 'Please enter a valid email address\n';

 if (!$w('#inputCompany').valid)
            validationMessage += 'Please enter a company name\n';

 if (!$w('#cbAgreeToTerms').checked)
            validationMessage += 'Please agree to terms and conditions\n';

        $w('#txtValidationMessage').text = validationMessage;
        $w('#txtValidationMessage').show();
        console.log(validationMessage);

    } else {

        $w('#txtValidationMessage').hide();
        wixData.query("MembersOnly")
            .eq("email", $w('#inputEmail').value)
            .find()
            .then(res => {
 if (res.length > 0) {
                    validationMessage += 'The email address you have entered already exists\n';
                    $w('#txtValidationMessage').text = validationMessage;
                    $w('#txtValidationMessage').show();
                    console.log("Email address already exists")

                } else {

 
                    wixData.save("MembersOnly", toSave)
                        .then((results) => {
    let item = results;
                        })
                        .catch((err) => {
 let errorMsg = err;
                        });

                    wixWindow.openLightbox("Thank you");
                    console.log("Member request saved")
                }
            })

        console.log("Submit button clicked");
    }
}

Many thanks,
Rachel

Hey
I see you use .save so I wonder if you have a Dataset on your page that you use and add this code to that Dataset. If you only use code you might a .new() somewhere in your code first that creates the record in the dataset? I have another project that new blank rows and added if we have the .new() in page load and not just before the save. I think you can use .save without using .new as well or just use the .insert instead of save.

Hi,
Instead of using:
wixData.save (“MembersOnly”, toSave)
Use insert method.

Good luck!
Roi.

Hi Roi,

Thank you for your response. The problem is I am using .onAfterSave to send an email on form submission…

$w("#dsMembersOnly").onAfterSave(sendFormData);

Do you know if there is another way around this?

Many thanks,
Rachel

I think the issue might be that I have connected my submit button to ‘submit’ as this appears to be the only way for .onAfterSave to complete. If I remove the connection I don’t get the duplicate entry but then the email does not send on form submission?

Have you solved the issue? i am having the same challenges. please help me with your solution.

@myfundinc Hi, this thread is pretty old. To get the best support, please create a new post with a detailed description of your issue, your code, and any screenshots. Please follow our posting guidelines here . Thank you!