<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Circles And Lambdas</title>
    <description>The latest articles on DEV Community by Circles And Lambdas (@circles_andlambdas_).</description>
    <link>https://dev.to/circles_andlambdas_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3899986%2F225ffbc2-b4a5-43d7-993b-412850a5bb6f.png</url>
      <title>DEV Community: Circles And Lambdas</title>
      <link>https://dev.to/circles_andlambdas_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/circles_andlambdas_"/>
    <language>en</language>
    <item>
      <title>Authentication Processes are fighting human nature</title>
      <dc:creator>Circles And Lambdas</dc:creator>
      <pubDate>Tue, 19 May 2026 09:25:49 +0000</pubDate>
      <link>https://dev.to/circles_andlambdas_/-authentication-processes-are-fighting-human-nature-4f1n</link>
      <guid>https://dev.to/circles_andlambdas_/-authentication-processes-are-fighting-human-nature-4f1n</guid>
      <description>&lt;p&gt;Question, how many passwords do you remember? &lt;/p&gt;

&lt;p&gt;Among all the services you registered for and created an account, do you remember any of the passwords used for every individual service? Do you remember the information you would use to login to those services? If you are like me, a human, the number of passwords you can remember would be between "a few" and "none". In other cases, it would be some absurd answer like using one password to secure all those accounts. But we will pretend that doesn't exist.&lt;/p&gt;

&lt;p&gt;This points to a very opaque fact about humans and digital systems: we do not remember things easily. According to Hermann Ebbinghaus, brains lose information over time without reinforcement. We don’t go out our way to reinforce dozens of passwords to memory. The number of services we become part of doesn't help that fact either. &lt;/p&gt;

&lt;p&gt;Humans are surprisingly stateless, just like computers, relying on brains to remember the important information. Without the brain remembering what we need to remember, we would be idling bodies without any purpose. I bring this up is because it is tied to my experience working with a product targeted towards the public. One recurring theme I was constantly dealing with was users creating multiple accounts. This created unique issues where all the information tied to a person was spread into multiple accounts. &lt;/p&gt;

&lt;p&gt;We typically ran into users with 3 to 4 accounts registered, and having trouble finding the one they paid for. One case had a user creating 3 accounts in one afternoon period.&lt;/p&gt;

&lt;p&gt;I tried multiple ways to combat this case, like limiting one phone number or email to one account, and requiring email addresses as necessary during registration. However, this led to other issues where users dropped off from the registration page when the registration failed due to missing required field. One user couldn't provide a working email to receive the verification link. I was naive to think users would not have an email address in the current digital age.&lt;/p&gt;

&lt;p&gt;I kept thinking about the strange phenomenon, and I came to some insights.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Users forget quickly
&lt;/h3&gt;

&lt;p&gt;We would reach out to users to try and diagnose where the problem was, and 3 out of 5 times users would forget the username they created for the account. It’s in our nature to forget things without having to constantly remind ourself. That would explain multiple social media accounts spreading over years.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The more the friction, the less the engagement.
&lt;/h3&gt;

&lt;p&gt;Friction hinders progress. It’s a given that if a process has a lot of caveats and necessary steps in order to complete a task, the number of people who complete the steps will be less. It will be even less when the task isn't a need. A step through the registration required users to verify the email in order to continue, but the complaints came in as soon as it was implemented. I argued it was for security reasons but the client comes first.&lt;/p&gt;

&lt;h2&gt;
  
  
  OTP: A 6 digit alternative to static passwords.
&lt;/h2&gt;

&lt;p&gt;OTPs or One Time Passwords are numbers or letters, typically 6 in number, sent to the user to authenticate a login attempt or a transaction attempts in the case of bank transactions. They were created typically to deal with the insecurity of a single static password, since the OTP was dynamically created and would expire after a set time. &lt;/p&gt;

&lt;p&gt;The dynamic nature was what drew me towards OTPs since it wasn't dependent on the user remembering a password created on a past date. A user could create an account with the name and phone number or email and request a password from the service in order to access it. This removes a lot of the initial friction since users are typically required to remember one piece of information to access the service. &lt;/p&gt;

&lt;p&gt;This had advantages to both users and the development team.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Users:&lt;/strong&gt;
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;One piece of information to remember (Email address or Phone number)&lt;/li&gt;
&lt;li&gt;No "Forgot Password" trap &lt;/li&gt;
&lt;li&gt;No duplicate accounts created using one number.&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Developers:&lt;/strong&gt;
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;Limited dependency on a static password.&lt;/li&gt;
&lt;li&gt;Built-In Verification flow (The contact is controlled by the one who receives the OTP)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;One thing I haven't pointed out is the assumption I had creating the authentication system. I had assumed since other systems followed the same flow, I would simply duplicate the flow, enter phone number and email address, create a password and click Register, and users would quickly adopt it.&lt;/p&gt;

&lt;p&gt;I was Wrong.&lt;/p&gt;

&lt;p&gt;Getting constant feedback that the typical flow was not working taught me that mental models cannot be duplicated. And just like this article, my conceived perception that OTPs will ease the authentication process might be placed on feeble assumptions. I am aware there are other far more impressive solutions like social authentication and Single Sign-On but they were not feasible on the codebase I was tasked on.&lt;/p&gt;

&lt;p&gt;Despite being this far into our technological journey as humans, the authentication systems that are prevalent right now lead to some unique scenarios that may not typically ease the user's experience on the system and it is exacerbated by the explosive number of systems that require user authentication. Use of simpler, quicker processes to accurately determine the user may lead to much better authentication and I am on the path to find these processes.&lt;/p&gt;

</description>
      <category>authentication</category>
      <category>ux</category>
      <category>software</category>
      <category>security</category>
    </item>
    <item>
      <title>EspoCRM Lead capture and Preflight Checks.</title>
      <dc:creator>Circles And Lambdas</dc:creator>
      <pubDate>Mon, 11 May 2026 15:36:50 +0000</pubDate>
      <link>https://dev.to/circles_andlambdas_/espocrm-lead-capture-and-preflight-checks-5g8p</link>
      <guid>https://dev.to/circles_andlambdas_/espocrm-lead-capture-and-preflight-checks-5g8p</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Here is how I manage to get my CRM and my website to communicate with each other.&lt;/p&gt;

&lt;p&gt;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.&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;I created the API link, created the web form and wrote the JavaScript lines to send the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;JavaScript&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;webToLeadFormElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lead_capture&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isSubmitting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;webToLeadFormElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isSubmitting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;formData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FormData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;webToLeadFormElement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hasEmpty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(([&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;website&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hasEmpty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;showError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please fill in all fields before submitting.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nx"&gt;isSubmitting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nf"&gt;setButtonState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;loading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;submitLead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;submitLead&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;API_LINK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;setButtonState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="nx"&gt;webToLeadFormElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;showError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Something went wrong. Please try again.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="nf"&gt;setButtonState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Capture failed:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nf"&gt;showError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Network error. Please check your connection.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nf"&gt;setButtonState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;isSubmitting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All was LGTM until I hit the send Inquiry button.&lt;br&gt;
Instead of a submitted form, nothing happened. The test data remained as it was. A process that I thought would be seamless and straight forward suddenly became not. As an experienced console.log() tester, I immediately went to the console to see what was up on that side. That is when I saw the following message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Console Log
    Submitting: {firstName: '', lastName: '', email: '', phoneNumber: '', inquiry: '', …}
    index.html:1 Access to fetch at 'http://localhost/espocrm/api/v1/LeadCapture/9dfb865ed229b56b2c053b27409ba6e8' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    index.html:567  POST http://localhost/espocrm/api/v1/LeadCapture/9dfb865ed229b56b2c053b27409ba6e8 net::ERR_FAILED
    submitLead @ index.html:567
    (anonymous) @ index.html:560Understand this error
    index.html:580 Capture failed: TypeError: Failed to fetch
        at submitLead (index.html:567:36)
&lt;/span&gt;&lt;span class="gp"&gt;        at HTMLFormElement.&amp;lt;anonymous&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;index.html:560:9&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My first thought was I was missing some headers on my JS fetch call, so I added &lt;code&gt;Access-Control-Allow-Origin: *&lt;/code&gt; as part of the headers, but the same error persisited. My forms were not submitting. I decided to go look for some other unfortunate developer with the same predicament as I had on the internet. Turns out there are request headers and response headers. Request Headers are sent by the browser, and Response headers MUST be sent by the server. I seem to forgot the back part in the back and forth of the Server-Client relationship.&lt;/p&gt;

&lt;p&gt;I came across an EspoCRM forum talking about the exact issue I had, and I was ready to hit the classic ctrl+c, ctrl+v move. My hopes were tested again, I did not find a code block to copy or any lines to paste. The only thing of use was a github issue link that discussed the problem. Following through the GitHub issue, A solution was proposed that included pasting a line, &lt;code&gt;'leadCaptureAllowOrigin' =&amp;gt; '*'&lt;/code&gt; into data\config.php file, assuming it would allow the Access-Control-Allow-Origin header to be "*".&lt;/p&gt;

&lt;p&gt;I followed the official workaround, cleared my cache, rebuilt my backend and went to test my patch. Still the same issue arose: No 'Access-Control-Allow-Origin' header is present on the requested resource. It was at this point that I was getting a bit worried of the whole lead capture idea.&lt;/p&gt;

&lt;p&gt;Frustrated, I copied the entire JS code, along with the error, and went crying to mother Claude. &lt;/p&gt;

&lt;p&gt;She was fortunate to hear my problems, and suggested I attempt to access a section that was not existent in my CRM, or I could use the official workaround &lt;code&gt;leadCaptureAllowOrigin&lt;/code&gt; and a third, more precise and elaborate idea of reconfiguring my .htaccess file. I had never touched the file in all my life, as my years of programming did not direct me to that file once. This made me a bit cautious, I did not want to take part in a all night diagnosis of a failed server.&lt;/p&gt;

&lt;p&gt;CORS or Cross Origin Resource Sharing is an HTTP-header based browser security mechanism that allows a server to indicate any origins(domain, scheme, or port) other than it own from which a browser should permit loading resources. The browser enforces this, it checks whether the server's response includes permission for the requesting origin before allowing the request to go through.&lt;/p&gt;

&lt;p&gt;From my understanding though, my website was not allowed to POST formData because it wasn't on the server's list. The &lt;code&gt;leadCaptureAllowOrigin&lt;/code&gt; line was incharge of telling the EspoCRM to allow all sites to send data to it. &lt;/p&gt;

&lt;p&gt;Claude suggested I reconfigure the file to include these lines into the .htaccess file in the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Header always set Access-Control-Allow-Origin "MY_WEBSITE_LINK"
    Header always set Access-Control-Allow-Methods "GET, POST, OPTIONS"
    Header always set Access-Control-Allow-Headers "Content-Type, Authorization"

    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ - [R=204,L]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I sort of understood the First three lines, but now the .htaccess directives is where I was getting lost. The third one specifically was where I was getting no connection to it, so I went runnin' for answers.&lt;/p&gt;

&lt;p&gt;Browser sends an OPTIONS request to the server, server matches ^(.*)$ to the API_LINK, R=204 tells Apache when the method is OPTIONS, return a 204 No Content Response immediately, - means don't rewrite the URL, R=204 sets the status Code and L stops further rewrite processing.&lt;/p&gt;

&lt;p&gt;Now this is the preflight check, that happens before the actual POST request, it ensures security by asking the server for permission before the actual request, according to Google.&lt;/p&gt;

&lt;p&gt;Once I pasted the code, and restarted my server, a different error now took the throne. A win is a win. &lt;/p&gt;

&lt;p&gt;That was indication that the code worked and the request was going through. I followed the error to EspoCRM logs and found out the code responsible for capturing the POST data from the form was appending the &lt;code&gt;leadCaptureAllowOrigin&lt;/code&gt; value as the origin, causing the error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$apiKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BadRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'No API key provided.'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$allowOrigin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'leadCaptureAllowOrigin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'*'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// $response-&amp;gt;setHeader('Access-Control-Allow-Origin', $allowOrigin);&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCaptureService&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;capture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$apiKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I commented out the assignment code, restarted my server, and rebuilt my backend. And Voila, the Leads were posting on my backend, hours of debugging, lots of syndromes, and Mother's help lead to it. That's what I consider a good session.&lt;/p&gt;

&lt;p&gt;I started with a simple goal of connecting my CRM and website lead to my interest on CORS being piqued. The .htaccess file I have always avoided came to the rescue (for today).&lt;/p&gt;

&lt;p&gt;If you are hitting the same CORS problem with EspoCRM(V 9.1.8) Web Lead Capture, here's the TLDR:&lt;/p&gt;

&lt;p&gt;1.Don't add CORS headers to your JavaScript fetch call - Not how it works.&lt;br&gt;
2.The &lt;code&gt;leadCaptureAllowOrigin&lt;/code&gt; in config.php doesnt work.&lt;br&gt;
3.Handle the OPTIONS preflight in &lt;code&gt;.htaccess&lt;/code&gt; and set the CORS headers there - That's where they belong.&lt;/p&gt;

&lt;p&gt;Let me settle down and learn what is .htaccess, I need more niche developer points. God knows there are few going around this days.&lt;/p&gt;

</description>
      <category>espocrm</category>
      <category>php</category>
      <category>http</category>
      <category>html</category>
    </item>
  </channel>
</rss>
