FROM CACHE - it_header

Modulo registrazione

Modulo registrazione

Tendency
Shopify Partner
14 0 2

Salve, 

 

Ho personalizzato il modulo di registrazione per consentire una registrazione più semplice al cliente e vari campi personalizzati. Sembra essere tutto ok, ma noto che dopo la registrazione i dati personalizzati non vengono raccolti e memorizzati in nessun campo della scheda cliente. Come posso far memorizzare i campi che ho aggiunto nella scheda cliente per indirizzi di fatturazione ecc...?

 

Incollo tutto il codice sviluppato qui in basso per capirci meglio.

 

{{ 'customer.css' | asset_url | stylesheet_tag }}

{%- style -%}
  .section-{{ section.id }}-padding {
    padding-top: {{ section.settings.padding_top | times: 0.75 | round: 0 }}px;
    padding-bottom: {{ section.settings.padding_bottom | times: 0.75 | round: 0 }}px;
  }

  @media screen and (min-width: 750px) {
    .section-{{ section.id }}-padding {
      padding-top: {{ section.settings.padding_top }}px;
      padding-bottom: {{ section.settings.padding_bottom }}px;
    }
  }
{%- endstyle -%}

<div class="customer register section-{{ section.id }}-padding">
  <svg style="display: none">
    <symbol id="icon-error" viewBox="0 0 13 13">
      <circle cx="6.5" cy="6.50049" r="5.5" stroke="white" stroke-width="2"/>
      <circle cx="6.5" cy="6.5" r="5.5" fill="#EB001B" stroke="#EB001B" stroke-width="0.7"/>
      <path d="M5.87413 3.52832L5.97439 7.57216H7.02713L7.12739 3.52832H5.87413ZM6.50076 9.66091C6.88091 9.66091 7.18169 9.37267 7.18169 9.00504C7.18169 8.63742 6.88091 8.34917 6.50076 8.34917C6.12061 8.34917 5.81982 8.63742 5.81982 9.00504C5.81982 9.37267 6.12061 9.66091 6.50076 9.66091Z" fill="white"/>
      <path d="M5.87413 3.17832H5.51535L5.52424 3.537L5.6245 7.58083L5.63296 7.92216H5.97439H7.02713H7.36856L7.37702 7.58083L7.47728 3.537L7.48617 3.17832H7.12739H5.87413ZM6.50076 10.0109C7.06121 10.0109 7.5317 9.57872 7.5317 9.00504C7.5317 8.43137 7.06121 7.99918 6.50076 7.99918C5.94031 7.99918 5.46982 8.43137 5.46982 9.00504C5.46982 9.57872 5.94031 10.0109 6.50076 10.0109Z" fill="white" stroke="#EB001B" stroke-width="0.7">
    </symbol>
  </svg>

  <h1>{{ 'customer.register.title' | t }}</h1>

  {%- form 'create_customer', novalidate: 'novalidate' -%}

    <!-- Sezione Nome e Cognome -->
    
    <div class="form-section" id="section-name">
      <div class="field">
        <input
          type="text"
          name="customer[first_name]"
          id="RegisterForm-FirstName"
          required
          {% if form.first_name %}
            value="{{ form.first_name }}"
          {% endif %}
          autocomplete="given-name"
          placeholder="{{ 'customer.register.first_name' | t }}"
        >
        <label for="RegisterForm-FirstName">{{ 'customer.register.first_name' | t }}</label>
      </div>

      <div class="field">
        <input
          type="text"
          name="customer[last_name]"
          id="RegisterForm-LastName"
          required
          {% if form.last_name %}
            value="{{ form.last_name }}"
          {% endif %}
          autocomplete="family-name"
          placeholder="{{ 'customer.register.last_name' | t }}"
        >
        <label for="RegisterForm-LastName">{{ 'customer.register.last_name' | t }}</label>
      </div>

     
      <!-- Company & Person  -->


   <div>
  
  <select id="customer-type" name="customer[type]">
    <option value="person">Person</option>
    <option value="company">Company</option>
  </select>
</div>

<div id="vat-number-field" style="display: none;">
  
  <input
    type="text"
    id="vat-number"
    name="customer[vat_number]"
    placeholder="Enter VAT Number"
  >
</div>

<script>
  document.addEventListener('DOMContentLoaded', function() {
    var customerTypeDropdown = document.getElementById('customer-type');
    var vatNumberField = document.getElementById('vat-number-field');

    function toggleVatNumberField() {
      vatNumberField.style.display = (customerTypeDropdown.value === 'company') ? 'block' : 'none';
    }

    customerTypeDropdown.addEventListener('change', toggleVatNumberField);

    // Mostra il campo VAT Number se l'opzione Company è selezionata inizialmente
    toggleVatNumberField();
  });
</script>


      

             <!-- Company & Person END  -->

      <!-- Address  -->
      

      <button type="button" id="btn-next-address">{{ 'customer.register.next' | t }}</button>
    </div>

    <!-- Sezione Indirizzo -->
    <div class="form-section" id="section-address" style="display: none;">
      <div class="field">
        <input
          type="text"  
          name="customer[Address]"
          id="RegisterForm-Address"
          {% if form.Address %}
            value="{{ form.Address }}"
          {% endif %}
          placeholder="{{ 'customer.register.address' | t }}"
          required
        >
        <label for="RegisterForm-Address">{{ 'customer.register.address' | t }}</label>
      </div>

      <div class="field">
        <input
          type="text"  
          name="customer[City]"
          id="RegisterForm-City"
          {% if form.City %}
            value="{{ form.City }}"
          {% endif %}
          placeholder="{{ 'customer.register.city' | t }}"
          required
        >
        <label for="RegisterForm-City">{{ 'customer.register.city' | t }}</label>
      </div>

      <div class="field">
        <input
          type="text"  
          name="customer[State]"
          id="RegisterForm-State"
          {% if form.State %}
            value="{{ form.State }}"
          {% endif %}
          placeholder="{{ 'customer.register.state' | t }}"
          required
        >
        <label for="RegisterForm-State">{{ 'customer.register.state' | t }}</label>
      </div>

      <div class="field">
        <input
          type="text"  
          name="customer[Zip]"
          id="RegisterForm-Zip"
          {% if form.Zip %}
            value="{{ form.Zip }}"
          {% endif %}
          placeholder="{{ 'customer.register.ZIP' | t }}"
          required
        >
        <label for="RegisterForm-Zip">{{ 'customer.register.ZIP' | t }}</label>
      </div>

      <!-- Aggiungi altri campi di indirizzo qui -->

      <button type="button" id="btn-prev-name">{{ 'customer.register.previous' | t }}</button>
      <button type="button" id="btn-next-contact">{{ 'customer.register.next' | t }}</button>
    </div>

    <!-- Sezione Contatto -->
    
    <div class="form-section" id="section-contact" style="display: none;">
    
      <!-- Campi di contatto -->
      
      <div class="field">
        <input
          type="tel"
          name="customer[Number]"
          id="RegisterForm-Number"
          required
          {% if form.Number %}
            value="{{ form.Number }}"
          {% endif %}
          autocomplete="tel"
          placeholder="{{ 'customer.register.number_r' | t }}"
          required
        >
        <label for="RegisterForm-Number">{{ 'customer.register.number_r' | t }}</label>
      </div>

      <div class="field">
        <input
          type="email"
          name="customer[email]"
          id="RegisterForm-email"
          {% if form.email %}
            value="{{ form.email }}"
          {% endif %}
          spellcheck="false"
          autocapitalize="off"
          autocomplete="email"
          aria-required="true"
          {% if form.errors contains 'email' %}
            aria-invalid="true"
            aria-describedby="RegisterForm-email-error"
          {% endif %}
          placeholder="{{ 'customer.register.email' | t }}"
          required
        >
        <label for="RegisterForm-email">{{ 'customer.register.email' | t }}</label>
      </div>

      <!-- Aggiungi altri campi di contatto qui -->

      <div class="field">
        <input
          type="password"
          name="customer[password]"
          id="RegisterForm-password"
          aria-required="true"
          {% if form.errors contains 'password' %}
            aria-invalid="true"
            aria-describedby="RegisterForm-password-error"
          {% endif %}
          placeholder="{{ 'customer.register.password' | t }}"
          required
        >
        <label for="RegisterForm-password">{{ 'customer.register.password' | t }}</label>
      </div>

      <div class="field">
        <input
          type="password"
          name="customer[password_confirmation]"
          id="RegisterForm-password_confirmation"
          aria-required="true"
          {% if form.errors contains 'password_confirmation' %}
            aria-invalid="true"
            aria-describedby="RegisterForm-password_confirmation-error"
          {% endif %}
          placeholder="{{ 'customer.register.password_confirm' | t }}"
          required
        >
        <label for="RegisterForm-password_confirmation">{{ 'customer.register.password_confirm' | t }}</label>
      </div>

      {%- if form.errors contains 'password' -%}
        <span id="RegisterForm-password-error" class="form__message">
          <svg aria-hidden="true" focusable="false">
            <use href="#icon-error" />
          </svg>
          {{ form.errors.translated_fields.password | capitalize }}
          {{ form.errors.messages.password }}.
        </span>
      {%- endif -%}

      <button type="button" id="btn-prev-address">{{ 'customer.register.previous' | t }}</button>
      <button type="submit">{{ 'customer.register.submit' | t }}</button>
    </div>
  {%- endform -%}

 <script>
  document.addEventListener('DOMContentLoaded', function() {
    var sections = document.querySelectorAll('.form-section');
    var btnNextAddress = document.getElementById('btn-next-address');
    var btnPrevName = document.getElementById('btn-prev-name');
    var btnNextContact = document.getElementById('btn-next-contact');
    var btnPrevAddress = document.getElementById('btn-prev-address');

    function showSection(sectionIndex) {
      for (var i = 0; i < sections.length; i++) {
        sections[i].style.display = 'none';
      }
      sections[sectionIndex].style.display = 'block';
    }

    function validateFields(sectionIndex) {
      var fields = sections[sectionIndex].querySelectorAll('input[required]');
      var isValid = true;
      var errorMessage = "Please fill in all required fields:";
      fields.forEach(function(field) {
        if (!field.value.trim()) {
          isValid = false;
          errorMessage += "\n- " + field.getAttribute('placeholder');
        }
      });
      if (!isValid) {
        alert(errorMessage);
      }
      return isValid;
    }

    btnNextAddress.addEventListener('click', function() {
      if (validateFields(0)) {
        showSection(1);
      }
    });

    btnPrevName.addEventListener('click', function() {
      showSection(0);
    });

    btnNextContact.addEventListener('click', function() {
      if (validateFields(1)) {
        showSection(2);
      }
    });

    btnPrevAddress.addEventListener('click', function() {
      showSection(1);
    });

    // Mostra la prima sezione inizialmente
    showSection(0);
  });
</script>

 

0 RISPOSTE 0