TESOL Advanced Enrollment — form code

Copy this code into the page on americantesol.com where the form should appear. The student pays on Stripe's secure checkout page, which opens in its own window, and lands on the ATI study page once paid. A cancelled payment comes back to the form.

<div id="ati-enroll">
  <style>
    #ati-enroll { width: 100%; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: #0a0a0a; max-width: 560px; margin: 0 auto; }
    #ati-enroll .ati-title { font-size: 20px; font-weight: 600; line-height: 1.3; margin: 0 0 20px; }
    #ati-enroll label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
    /* 16px inputs stop iOS Safari zooming in when a field is tapped */
    #ati-enroll input, #ati-enroll select { width: 100%; box-sizing: border-box; height: 42px; padding: 0 12px; border: 1px solid #d4d4d8; border-radius: 8px; font-size: 16px; background: #fff; color: #0a0a0a; }
    #ati-enroll input:focus, #ati-enroll select:focus { outline: none; border-color: #a1a1aa; box-shadow: 0 0 0 3px rgba(161,161,170,.25); }
    #ati-enroll .ati-field { margin-bottom: 16px; }
    #ati-enroll .ati-row { display: flex; gap: 16px; }
    #ati-enroll .ati-row > * { flex: 1; }
    #ati-enroll button { width: 100%; height: 48px; margin-top: 8px; border: 0; border-radius: 8px; background: #18181b; color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; }
    #ati-enroll button:disabled { opacity: .6; cursor: default; }
    #ati-enroll .ati-error { color: #b91c1c; font-size: 14px; margin: 10px 0 0; }
    /* the course is a single fixed choice, so it reads as a selected row and not a field */
    #ati-enroll .ati-course-choice { display: flex; align-items: center; gap: 10px; font-weight: 400; border: 1px solid #d4d4d8; border-radius: 8px; padding: 12px; margin: 0; cursor: pointer; }
    #ati-enroll .ati-course-choice input { width: auto; height: auto; margin: 0; accent-color: #18181b; }
    /* phones: this column has no width of its own, so give it the full page width */
    @media (max-width: 799px) {
      .row > .col-md-6 { flex: 0 0 100%; max-width: 100%; }
    }
    /* stack the name fields sooner so they don't crowd on phones */
    @media (max-width: 600px) { #ati-enroll .ati-row { flex-direction: column; gap: 0; } }
  </style>

  <form id="ati-form" novalidate>
    <h2 class="ati-title">TESOL Advanced</h2>
    <div class="ati-row">
      <div class="ati-field">
        <label for="ati-first">First name *</label>
        <input id="ati-first" name="first_name" type="text" autocomplete="given-name" required>
      </div>
      <div class="ati-field">
        <label for="ati-last">Last name *</label>
        <input id="ati-last" name="last_name" type="text" autocomplete="family-name" required>
      </div>
    </div>
    <div class="ati-field">
      <label for="ati-email">Email *</label>
      <input id="ati-email" name="email" type="email" autocomplete="email" required>
    </div>
    <div class="ati-field">
      <label for="ati-phone">Phone number *</label>
      <input id="ati-phone" name="phone" type="tel" autocomplete="tel" required>
    </div>
    <div class="ati-field">
      <label for="ati-education">Highest level of education *</label>
      <select id="ati-education" name="education" required>
        <option value="">Select your education level</option>
        <option>High School / GED</option>
        <option>Some College</option>
        <option>Associate Degree</option>
        <option>Bachelor's Degree</option>
        <option>Master's Degree</option>
        <option>Doctorate</option>
        <option>Other</option>
      </select>
    </div>
    <div class="ati-field">
      <label id="ati-course-label">Course of enrollment *</label>
      <label class="ati-course-choice" for="ati-course">
        <input id="ati-course" name="course" type="radio" value="advanced" checked required aria-labelledby="ati-course-label ati-course-text">
        <span id="ati-course-text">TESOL Advanced Certification — $295.00</span>
      </label>
    </div>
    <button id="ati-submit" type="submit">Enroll</button>
    <p class="ati-error" id="ati-error" role="alert" hidden></p>
  </form>
</div>

<script>
(function () {
  var COURSE_KEY = 'advanced';
  var ENDPOINT = 'https://americantesol.base44.app/functions/createCourseCheckout';

  var form = document.getElementById('ati-form');
  var button = document.getElementById('ati-submit');
  var errorEl = document.getElementById('ati-error');
  var courseEl = document.getElementById('ati-course');

  function value(id) { return document.getElementById(id).value.trim(); }
  function fail(message) {
    errorEl.textContent = message;
    errorEl.hidden = false;
    button.disabled = false;
    button.textContent = 'Enroll';
  }

  form.addEventListener('submit', async function (event) {
    event.preventDefault();
    errorEl.hidden = true;

    var student = {
      first_name: value('ati-first'),
      last_name: value('ati-last'),
      email: value('ati-email'),
      phone: value('ati-phone'),
      education: value('ati-education')
    };

    if (!student.first_name || !student.last_name || !student.email || !student.phone || !student.education || !courseEl.checked) {
      fail('Please complete every required field.');
      return;
    }
    if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(student.email)) {
      fail('Please enter a valid email address.');
      return;
    }

    button.disabled = true;
    button.textContent = 'Starting secure checkout…';

    // Checkout is a page of its own, which cannot open inside a frame. When the
    // form is framed the tab is opened here, still in the click, so the browser
    // keeps the visitor's intent; otherwise this page goes there itself.
    var framed = window.self !== window.top;
    var checkoutTab = framed ? window.open('', '_blank') : null;
    if (framed && !checkoutTab) {
      fail('Allow popups to continue to checkout.');
      return;
    }
    if (checkoutTab) checkoutTab.opener = null;

    try {
      // Hosted checkout: no card fields and no Stripe script on this page. The
      // server prices the course and answers with the Stripe page to open.
      var res = await fetch(ENDPOINT, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          course: COURSE_KEY,
          hosted: true,
          // A paid student lands on the ATI study page.
          successUrl: 'https://americantesol.com/study.html',
          // A cancelled payment comes back to this page, form and all. Inside a
          // frame that page is the one holding the frame, which is the referrer.
          cancelUrl: framed && document.referrer ? document.referrer : window.location.href,
          student: student
        })
      });
      var data = await res.json();
      if (!res.ok || !data.url) throw new Error(data.error || 'Checkout could not be started.');

      if (checkoutTab) {
        checkoutTab.location.replace(data.url);
      } else {
        window.location.assign(data.url);
      }
    } catch (error) {
      if (checkoutTab) checkoutTab.close();
      fail(error.message || 'Checkout could not be started. Please try again.');
    }
  });
})();
</script>

We don't use tracking or advertising cookies. Only the storage needed to keep you signed in. See our Privacy Policy.