src/ApplicationBundle/Modules/HoneybeeWeb/Resources/views/pages/inc/intent_form.html.twig line 1

Open in your IDE?
  1. {# WEB-2 §29 — the shared buyer-intent form. SHORT by law: name, work email, company,
  2.    country + only the intent's own extras. Posts to the one endpoint; WebIntentCore is
  3.    the validation contract. Caller sets: intent, cta (button label), extras (list of
  4.    {name, label, type?, options?}) — extras default to none (the demo form baseline). #}
  5. {% set extras = extras|default([]) %}
  6. <form class="pp-form" id="ppIntentForm" data-intent="{{ intent }}"
  7.       action="{{ url('honeybee_intent_request', {'intent': intent}) }}" method="post">
  8.     <div class="row">
  9.         <div><label>Name *</label><input name="name" required maxlength="120"></div>
  10.         <div><label>Work email *</label><input name="email" type="email" required maxlength="190"></div>
  11.     </div>
  12.     <div class="row">
  13.         <div><label>Company{% if intent == 'partner' %} *{% endif %}</label>
  14.             <input name="company" maxlength="190" {% if intent == 'partner' %}required{% endif %}></div>
  15.         <div><label>Country</label><input name="country" maxlength="90"></div>
  16.     </div>
  17.     {% for f in extras %}
  18.         <label>{{ f.label }}</label>
  19.         {% if f.options is defined %}
  20.             <select name="{{ f.name }}">
  21.                 <option value=""></option>
  22.                 {% for opt in f.options %}<option>{{ opt }}</option>{% endfor %}
  23.             </select>
  24.         {% else %}
  25.             <input name="{{ f.name }}" maxlength="300">
  26.         {% endif %}
  27.     {% endfor %}
  28.     <label>Anything we should know?</label>
  29.     <textarea name="note" rows="3" maxlength="2000"></textarea>
  30.     <button type="submit">{{ cta }}</button>
  31.     <div class="ok"></div>
  32.     <div class="err"></div>
  33. </form>
  34. <script>
  35. (function () {
  36.     var f = document.getElementById('ppIntentForm');
  37.     if (!f) return;
  38.     f.addEventListener('submit', function (e) {
  39.         e.preventDefault();
  40.         var btn = f.querySelector('button'); btn.disabled = true;
  41.         fetch(f.action, { method: 'POST', body: new FormData(f) })
  42.             .then(function (r) { return r.json(); })
  43.             .then(function (j) {
  44.                 var box = f.querySelector(j.success ? '.ok' : '.err');
  45.                 box.textContent = j.message || (j.success ? 'Sent.' : 'Something went wrong.');
  46.                 box.style.display = 'block';
  47.                 if (j.success) {
  48.                     f.querySelectorAll('input,select,textarea').forEach(function (i) { i.value = ''; });
  49.                     // WEB-5 §33: form_complete with the §29 intent as meta
  50.                     if (window.hbWa) { window.hbWa('form_complete', f.getAttribute('data-intent') || ''); }
  51.                 }
  52.                 else { btn.disabled = false; }
  53.             })
  54.             .catch(function () {
  55.                 var box = f.querySelector('.err');
  56.                 box.textContent = 'Could not send — please try again or email us.';
  57.                 box.style.display = 'block'; btn.disabled = false;
  58.             });
  59.     });
  60. })();
  61. </script>