Documentation • Technical Reference

Web2Phone Embed.js Reference

embed.js is the lightweight browser script that powers Web2Phone’s copy-and-paste forms. It intercepts form submissions, sends data to Web2Phone, and displays basic success or error feedback.

This page is for developers who want to understand exactly how the embed script works. If you just want a working form quickly, start with the Getting Started guide.

When should I use embed.js?

Most users should copy the full embed snippet from the Web2Phone dashboard. It includes everything needed to submit a form:

<form data-web2phone="form"
  data-public-key="YOUR_PUBLIC_KEY"
  data-endpoint="https://web2phone.co.uk/api/v1/submit/">

  <input name="name" required>
  <input name="email" type="email" required>
  <textarea name="message" required></textarea>

  <button type="submit">Send</button>
  <p data-w2p-output></p>
</form>

<script src="https://web2phone.co.uk/static/formsapp/js/embed.js"></script>

As long as the data attributes and script tag are present, embed.js will handle submission and feedback automatically.

Required data attributes

data-web2phone

Marks the form as managed by Web2Phone.

<form data-web2phone="form">

data-public-key

Identifies which Web2Phone form should receive the submission. This key is shown in your dashboard.

data-public-key="YOUR_PUBLIC_KEY"

data-endpoint

The Web2Phone API endpoint that receives submissions.

https://web2phone.co.uk/api/v1/submit/

data-w2p-output (optional)

An element where status messages are displayed.

<p data-w2p-output></p>

What data does embed.js send?

  1. Prevents the browser’s default form submission.
  2. Collects all fields with a name attribute.
  3. Sends a POST request including:
    • Your public key
    • All form field values
    • Browser origin information used to validate against your Allowed Domains list
⚠️

Allowed Domains rules

  • Enter the hostname only (e.g. example.com)
  • No http:// or https://
  • No paths or trailing slashes
  • No wildcards
  • example.com automatically allows www.example.com

Success & error behaviour

  • On success, a confirmation message is shown and delivery begins (WhatsApp or email).
  • On error, a generic message is shown and the form remains filled.

Successful submissions are not stored in the dashboard. Only queued or failed deliveries appear there.

Common integration tips

  • Only one embed.js script tag is needed per page.
  • Multiple Web2Phone forms per page are supported.
  • Use clear field names for readable notifications.
  • Always ensure Allowed Domains matches the hostname the browser shows.