Webflow Form ONSUBMIT

I have a webflow form that I would like call a local javascript upon form submit to put the form data into a local cookie. The redirected url page would then use javascript to read the cookie allowing personalization of the thank you message back to the user. Is there a way to implement a local javascript call upon submission of a webflow form?

Here is an example of a self scripted form that works OK:

<form name="FreeEstimate" method="POST" onsubmit="return CookieTheValues()" 
      action="http://www.example.com/cgi-bin/FormMail.pl">
1 Like

Additional information. I have been scripting the entire form via embedded code but would like to use the Webflow form capabilities and get rid of the custom code. The reason for the onsubmit call to set a cookie is the client has a newspaper promotion going on and they want to match the referral data from the newspaper with the forms submitted to track success rates.

Hi @jetski777, so sorry for the delay in getting some response about the question using onsubmit. Onsubmit is not a supported attribute at the moment in Webflow using custom attributes.

A workaround that may help, is to redirect the form to a success page in your site (create a success page) and then put an embed widget into the success page just under the body element, with a call to the script you are wanting to execute.

Take a peek at this article: http://help.webflow.com/faq/how-to-add-custom-head-and-body-code-to-a-webflow-site

If you need some additional help with this, share the read-only link to the site and I am happy to take a look: Share a read-only link | Webflow University

I hope this helps!

2 Likes

Your work-around will not work. Currently, using embedded code for the entire form, an ONSUBMIT call is made when the user presses submit which saves all of the form fields in a local cookie. The success page then reads the cookie to personalize the response back to the user (“Thank you Mr Smith, we will contact you at …”). This embedded code form works OK, but the customer wants the form on multiple pages and I had hoped to use the Webflow form object rather than embedded code. Guess I will have to use the embedded code form for now.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.