Most "sign here" widgets are a canvas and nothing else. If the script fails to load, if someone uses a keyboard, or if a screen reader is involved, there is simply no way to sign. We needed a signature field for waivers and photo releases in Formgong, and we wanted it to fail the other way round: the plain HTML should already be a working signature, and the drawing pad should be a bonus on top.
Here is how it ended up, including the one bug that every test missed and a real phone found in about two seconds.
The typed name is the signature
In the US, the ESIGN Act says a signature can't be refused just because it is electronic, and it defines an electronic signature as a symbol "adopted by a person with the intent to sign". A typed full name next to an "I agree" tick box meets that. So the base field is boring on purpose:
<label>Signature: type your full name <input type="text" name="signature" required autocomplete="name" data-formgong-signature> </label> required stops an empty submit with the browser's own message. autocomplete="name" lets the phone fill it in. Nothing here needs JavaScript, and it works with a keyboard and a screen reader.
The terms sit right above the tick box, in the same form, so nobody agrees to something they never had on screen:
<div class="fg-terms"><p>I understand the activity involves risk…</p></div> <label><input type="checkbox" name="agree" value="yes" required> I have read this and I agree to it</label> The pad: a canvas that writes into a file input
The pad only appears when the form can carry a file (enctype="multipart/form-data"), because the drawing travels as a real upload, not as a base64 string stuffed into a text field. That keeps the server path identical to any other file: the same size limits, the same virus scan, the same link in the notification email.
The trick is that a file input's files can be replaced with a DataTransfer list. After every stroke we turn the canvas into a PNG and drop it into a hidden input:
function save() { const out = document.createElement("canvas"); out.width = canvas.width; out.height = canvas.height; const o = out.getContext("2d"); o.fillStyle = "#fff"; // a white background reads the same in every mail client o.fillRect(0, 0, out.width, out.height); o.drawImage(canvas, 0, 0); const data = atob(out.toDataURL("image/png").split(",")[1]); const bytes = new Uint8Array(data.length); for (let i = 0; i < data.length; i++) bytes[i] = data.charCodeAt(i); const list = new DataTransfer(); list.items.add(new File([bytes], "signature.png", { type: "image/png" })); fileInput.files = list.files; // fileInput.name = "signature_drawn" } Two details that matter more than they look:
- Save on pointer-up, not on submit.
canvas.toBlobis async, and you can't hold a submit event while you wait for it. Doing the work at the end of each stroke means the file input is always current when the form goes, whether it is a plain POST or someone's ownfetch(new FormData(form))handler. - Scale for the screen. The canvas is sized to
getBoundingClientRect() × devicePixelRatiowithsetTransform(ratio, 0, 0, ratio, 0, 0), otherwise the strokes look blurry on a phone. A resize (turning the phone sideways) clears the pad, the same as pressing Clear, rather than stretching the drawing.
Drawing itself is three pointer events (pointerdown, pointermove, pointerup) with setPointerCapture, and touch-action: none on the canvas so the page doesn't scroll while you sign.
The bug the tests didn't catch
The first version inserted the pad right after the input with input.insertAdjacentElement("afterend", pad). The tests were happy: the script parsed, the file appeared, the right name came through.
Then I drew a line on it in Chrome and the name box above lit up with a focus ring. Every stroke. It took me a minute to see why: the input sits inside its <label>, so "right after the input" is still inside the label, and clicking anywhere inside a label focuses the control it belongs to. On a phone that pops the keyboard up the moment you put your finger down to sign. Lovely.
Moving the pad out of the label fixed it:
const host = input.closest("label") || input; host.insertAdjacentElement("afterend", pad); A day later, signing a real form on production turned up one more: a form that had uploads switched on only for the drawing also showed a generic "Attachments" box. Harmless, but odd on a waiver. Neither problem is visible in the markup. You only notice them when you sign something.
What actually arrives
I signed a test waiver on 19 November on the form's own page: typed a name, scribbled, ticked the box, hit Sign. Fifteen seconds later Gmail had the notification with every answer, agree: yes, the typed name, and a link to signature.png. 10,884 bytes, 924 by 280, white background, my two terrible lines in the middle.
The liability waiver template on formgong.com has four versions with the pad already on, if you want to poke at it.
One thing I still go back and forth on: we treat the drawing as optional and the typed name as the real signature. Some tools require the drawing. Which way would you go, and why?
