🚀 EspoCRM Lead capture and Preflight Checks.
Last week as I was trying to integrate EspoCRM's lead capture form with my website, I ran into a peculiar issue. Every time I would try to submit a form, whether filled or not, it wouldn't go through to my CRM. I kept getting a CORS Policy Error: My domain wasn't matching something called Access-Control-Allow-Origin. In my years of development, I was abstracted from CORS issues by frameworks and now it had caught up to me. Trying to diagnose the problem led me deeper and deeper into something I wasn't familiar with. Here is how I manage to get my CRM and my website to communicate with each other. In EspoCRM, there is a way to capture leads through an HTML form and have potential leads logged into the system. It uses an API token to identify the source of the lead and who is the owner once a lead fills the form. Once a web lead capture API is created, a link is created and it will be used for the connection and capture. EspoCRM, to their credit, also provides a composer package that handles the form submission. I however opted for the JavaScript fetch option as it was more flexible for my project and way efficient to implement. I created the API link, created the web form and wrote the JavaScript lines to send the data. JavaScript const webToLeadFormElement = document.getElementById("lead_capture"); let isSubmitting = false; webToLeadFormElement.addEventListener("submit", (e) => { e.preventDefault(); if (isSubmitting) return; const formData = new FormData(webToLeadFormElement)...
👉 Read more: https://dev.to/circles_andlambdas_/espocrm-lead-capture-and-preflight-checks-5g8p
