Files
supermarket/internal/web/templates/sites-forms.html
T
davidandClaude Opus 5.5 2c42857419 Phase 6 part 3: website lead forms into EspoCRM
Sites → Lead forms sets up the site's forms to create EspoCRM Leads
through its Lead Capture: the address saved and tested with a CORS
preflight, and a pull request adding a script that maps the form's fields
onto a Lead (campaign, page and form in the description). Plausible's
Lead goal is imported per signal as interested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:54:26 -07:00

65 lines
5.2 KiB
HTML

{{define "content"}}{{with .Data}}{{$d := .}}
<div class="heading"><h1>Lead forms</h1></div>
<p class="lede">Your website's forms ("send me a cost comparison", "become a partner") send each answer to EspoCRM as a new Lead, using EspoCRM's own Lead Capture: Supermarket only runs on this computer, so the forms can't post to it. The Lead's description says which form, which page, and which campaign brought the visitor; Plausible counts the forms sent per buying signal.</p>
{{if not .Sites}}
<section class="card empty"><p>Add your website and its Hugo repository under <a href="/settings/profile">Settings → Profile</a> first.</p></section>
{{else}}
{{if gt (len .Sites) 1}}<nav class="tabs">{{range .Sites}}<a href="/sites/forms?site={{.Index}}" {{if and $d.Current (eq .Index $d.Current.Index)}}aria-current="page"{{end}}>{{.URL}}</a>{{end}}</nav>{{end}}
{{with .Current}}{{$cur := .}}
{{if .Err}}<section class="card"><p class="warn-text">{{.URL}}: {{.Err}}.</p></section>{{else}}
{{if not $d.HasSynced}}
<section class="card empty"><p>Read {{.Repo}} under <a href="/sites?site={{.Index}}">Sections and pages</a> first.</p></section>
{{else}}{{with $d.State}}
<section class="card">
<h2>Now</h2>
{{if $d.Connected}}<p class="ok">Connected: the forms on {{$cur.URL}} send their answers to EspoCRM.</p>
{{else if .Action}}<p>The forms post to <code>{{.Action}}</code>{{if not .Patched}}, without Supermarket's mapping{{end}}.</p>
{{else}}<p>The forms open an email with the answers filled in: they don't post anywhere yet.</p>{{end}}
{{with .Pages}}<p class="small">Pages with a form: {{join . ", "}}</p>{{else}}<p class="small muted">No page has a form section yet. The page builder can add one where the site has the <code>form</code> section type.</p>{{end}}
{{if not .Supported}}<p class="warn-text">This site's form section doesn't post the way Supermarket knows, so it can't be connected automatically.</p>{{end}}
</section>
{{end}}{{end}}
<section class="card">
<h2>1. In EspoCRM</h2>
<ol>
<li>Open {{with $d.CRM}}<a href="{{.}}" target="_blank" rel="noopener noreferrer">EspoCRM</a>{{else}}EspoCRM{{end}} as an administrator: <em>Administration → Lead Capture → Create Lead Capture</em>.</li>
<li>Name it after the site, tick <em>Is Active</em>, and under <em>Payload Fields</em> add: {{join $d.Payload ", "}}.</li>
<li>Optional: a <em>Campaign</em> (for EspoCRM's own campaign statistics), a <em>Target List</em>, a <em>Target Team</em>, and <em>Double Opt-in</em> if people should confirm by email.</li>
<li>Save, and copy the <em>API URL</em> it shows: <code>https://…/api/v1/LeadCapture/…</code>.</li>
</ol>
<p class="small muted">Your site must be allowed to post to the CRM: EspoCRM allows every site by default (<code>leadCaptureAllowOrigin</code> in its <code>data/config.php</code>). The test below checks it.</p>
</section>
<form method="post" action="/sites/forms/save" class="card">
<h2>2. The Lead Capture's address</h2>
<input type="hidden" name="site" value="{{.Index}}">
<label>API URL <input name="capture" value="{{$d.Capture}}" placeholder="{{or $d.CRM "https://espocrm.example.com"}}/api/v1/LeadCapture/…"></label>
<button type="submit" class="secondary" data-busy="Testing…">Save and test</button>
<p class="small muted">The test asks the CRM whether {{.URL}} may post to it, the way a browser would. Nothing is created.</p>
</form>
<form method="post" action="/sites/forms/connect" class="card">
<h2>3. Connect the forms</h2>
<input type="hidden" name="site" value="{{.Index}}">
<p>Opens a pull request on {{.Repo}} that sets the forms' address, adds a small script mapping their fields onto a Lead's (name, email, organization, phone; the rest, the page and the campaign go in the description), and has the form section post through it. Merging publishes it.</p>
{{with $d.PR}}<p>{{if eq .State "merged"}}<span class="ok">Merged.</span> Send a test form on the live site and look for the Lead in EspoCRM.{{else if eq .State "closed"}}The last pull request was closed without merging.{{else}}A pull request is open{{end}} <a href="{{.URL}}" target="_blank" rel="noopener noreferrer">{{.URL}} ↗</a> <span class="small muted">{{ago .At}}</span></p>{{end}}
<button type="submit" data-busy="Opening…" {{if or (not $d.Capture) (not $d.Gitea)}}disabled{{end}}>{{if $d.Connected}}Open it again{{else}}Open the pull request{{end}}</button>
</form>
{{end}}
{{end}}
{{end}}
<h2>Forms sent, by buying signal</h2>
{{if not .Plausible}}<p class="help">Counted from Plausible: save its key under <a href="/settings/tracking">Settings → Website &amp; sales</a>.</p>{{end}}
<p class="small muted">The forms tell Plausible when they're sent (a <code>{{.Goal}}</code> event). Add a <code>{{.Goal}}</code> goal (a custom event) in Plausible, and the daily import counts the ones from visits tagged with a signal as <em>interested</em> on its scorecard.</p>
{{with .Leads}}
<div class="table-wrap"><table class="compact">
<thead><tr><th>Day</th><th>Signal</th><th class="num">Forms</th><th>From</th></tr></thead>
<tbody>{{range .}}<tr><td>{{.At.Format "2 Jan 2006"}}</td><td>{{.Signal}}</td><td class="num">{{.Count}}</td><td class="small">{{.Note}}</td></tr>{{end}}</tbody>
</table></div>
{{else}}<p class="help">None counted yet.</p>{{end}}
{{end}}{{end}}