The forms.js script

The forms.js script follows the BackMyForm forms of a page while the visitors fill them: it records when they start, the forms they leave without sending them, and, if you want, the values they typed.

Adding the script

Add the script to the pages of your forms, once per page:

index.html

<script src="https://submit.backmyform.com/f/forms.js" defer></script>

The script follows every form whose action is a BackMyForm endpoint: there is nothing else to set up. It never changes how the forms are sent: they are sent by the browser, or by your code, as without it. When the script is blocked or fails to load, the forms work the same.

The script is optional: a form receives its submissions without it. A form sent with JavaScript must still have its action on the endpoint, or the script ignores it (see JavaScript).

What it records

With the script, the submissions of a form have:

  • the time to respond: startedAt is when the visitor started to fill the form, at their first input;
  • the not finished submissions: a form started and not sent after 30 minutes without activity is listed in the not finished submissions, and sends the submission.abandoned webhook event;
  • the partial submissions, when they are enabled on the form: the values typed by the visitor are saved while they type, so that a not finished submission has them.

The partial submissions, and the submission.started and submission.abandoned webhook events, need a plan that includes the partial submissions.

Without the script

The submissions sent are all received, but BackMyForm only learns about a visitor when they send the form:

Without the scriptWith the script
startedAt is null: no time to respondstartedAt is the first input of the visitor
The forms started and not sent are unknownThey are listed as not finished submissions
The values typed before leaving are lostThey are saved, with the partial submissions
No submission.started and submission.abandoned webhook eventsThe events are sent

Partial submissions

The partial submissions are off by default: turn them on in the settings of the form, or with partialSubmissionsEnabled in PUT /v1/forms/:id. The values are then saved 2.5 seconds after the visitor stops typing, and when they leave the page.

These values are never saved before the submission:

  • the files;
  • the password fields (type="password");
  • the payment card fields (an autocomplete value starting with cc-, like cc-number);
  • the fields inside an element with the data-backmyform-ignore attribute.

Ignored fields

<form action="https://submit.backmyform.com/f/k3x9q2mf" method="POST">
	<input type="email" name="email" />
	<div data-backmyform-ignore>
		<input type="text" name="social_security_number" />
	</div>
	<button type="submit">Send</button>
</form>

The ignored fields are still sent with the final submission, as the other ones.

How it works

On the first input of a visitor, the script starts a submission and adds its id to the form, in a hidden _backmyform_submission_id field. When the form is sent, the submission started is completed with the final values: it is received like any other submission. A form used again on the same page, like a form in a dialog, starts a new submission.

The script also follows the forms in the shadow DOM of web components.