Submit a form programatically

Hi all,

I want to submit a form not just on the submit button press but via code in an event handler.

Is it possible to do something like

	$w('#form1').submit() 
	$w('#wixForms1').submit() 

Or fire the form’s submit button/event handler

	$w('#submitbutton').submit() 
	$w('#submitbutton').click() 

thanks,
Dave

import wixData from  'wix-data';
$w.onReady(() => {
        $w("#button").onClick(event => {
                let toSubmit = {
                        name: $w("#input1").value,
                        phone: $w("#input2").value,
                        //etc...
                }
        wixData.insert("CollectionName", toSubmit);
    })
})

Hi JD,

Really appreciate your answer. I’ve done what you suggest and have the data saving to a dataset. The issue is the form itself doesn’t submit, so an attached automation does not fire. Any ideas?

I’ve googled for firing an automation from corvid but no luck.

regards,
Dave

There are limitations on Wix Automations and Wix Ascend. Not everything is codable. But if you give us more context on what your actual goal is maybe we could suggest other alternatives if possible. (Such as a job scheduler: https://support.wix.com/en/article/corvid-scheduling-recurring-jobs#:~:text=Visit%20the%20Corvid%20by%20Wix,and%20when%20to%20run%20it. )

Right now it sounds like you want to create an automation hack by submitting a form.

What is it that you are trying to automate? An email? Or something else?

And when are you trying to automate it? When the user is on the site doing something? Or when they are not on the site?

Hi Nayeli,

Sure, I’ll start at the start :slight_smile:

I’ve created an appointment booking form for a company with a number of locations. Each individual store has it’s own contact email address (saved in a drop down). When the user makes their booking request the store needs to be alerted to the booking, and the customer also needs a confirmation email. So really all I want is two emails going out at the same time.

I have seen an email via sendgrid example going around but that is relying on a third party service and hand coding the email content. Not something simple I can hand over to the end users to tweak in future.

I couldn’t see a way to set up two email automations from the same form, so my cunning plan was to dump all the inputs into a second hidden form (swapping the store email into the email field) and then programtically submit this second form, launching it’s own email automation. Two forms, two email automations. Done

Thanks for your help,
Dave