custom/static-plugins/shopping-experiences/src/Resources/views/storefront/element/cms-element-simple-contact-form.html.twig line 1

Open in your IDE?
  1. {% block simple_contact_form %}
  2.     {% set config = element.fieldConfig.elements %}
  3.     {% set confirmationText = element.translated.config.confirmationText.value|replace({'\n': '<br>'}) %}
  4.     <div id="simpleContactForm" class="cms-element-{{ element.type }}">
  5.         <div class="row">
  6.             <div class="col-lg-12">
  7.                 <div class="card simple-contact-form-box-content">
  8.                     <div class="card-body">
  9.                         <div class="simple-contact-form-text">
  10.                             {% block simple_contact_form_text %}
  11.                                 {% if config.headline != '' %}<h4
  12.                                         class="simple-contact-form-headline simple-headline-dot-sm">{{ config.headline.value }}</h4>{% endif %}
  13.                                 {% if config.text != '' %}<p>{{ config.text.value }}</p>{% endif %}
  14.                             {% endblock %}
  15.                         </div>
  16.                         {% block simple_contact_form_input %}
  17.                         {% block simple_contact_form_fields %}
  18.                         <div class="form-row">
  19.                             <div class="col-md-6">
  20.                                 {% block simple_contact_form_input_first_name %}
  21.                                     {% sw_include '@Storefront/storefront/element/simple-contact-form/form-input.html.twig'
  22.                                         with {
  23.                                         fieldName: 'firstName',
  24.                                         required: true,
  25.                                         placeholder: 'wexo-cms.elements.simple-contact-form.fields.name'|trans
  26.                                     } %}
  27.                                 {% endblock %}
  28.                             </div>
  29.                             <div class="col-md-6">
  30.                                 {% block simple_contact_form_input_email %}
  31.                                     {% sw_include '@Storefront/storefront/element/simple-contact-form/form-input.html.twig'
  32.                                         with {
  33.                                         fieldName: 'email',
  34.                                         type: 'email',
  35.                                         required: true,
  36.                                         placeholder: 'wexo-cms.elements.simple-contact-form.fields.mail'|trans
  37.                                     } %}
  38.                                 {% endblock %}
  39.                             </div>
  40.                             <div class="col-12">
  41.                                 {% block simple_contact_form_input_comment %}
  42.                                     {% sw_include '@Storefront/storefront/element/simple-contact-form/form-input.html.twig'
  43.                                         with {
  44.                                         fieldName: 'comment',
  45.                                         required: true,
  46.                                         input: 'textarea',
  47.                                         placeholder: 'wexo-cms.elements.simple-contact-form.fields.comment'|trans
  48.                                     } %}
  49.                                 {% endblock %}
  50.                             </div>
  51.                         </div>
  52.                     </div>
  53.                     {% endblock %}
  54.                     {% block simple_contact_form_submit %}
  55.                         <div class="d-flex justify-content-center">
  56.                             <button type="submit"
  57.                                     class="btn simple-btn-hover-icon-primary simple-contact-form-submit simple-icon-arrows-white"
  58.                                     onclick="submitContactForm(this)">
  59.                                 {{ "wexo-cms.elements.simple-contact-form.submit"|trans }}
  60.                             </button>
  61.                         </div>
  62.                     {% endblock %}
  63.                     <div style="position: absolute; left: -5000px;" aria-hidden="true">
  64.                         <input type="text"
  65.                                id="contactFormValidator"
  66.                                name="b_d41cb534d0e79c26d3eea7815_38067263f9"
  67.                                tabindex="-1" value="">
  68.                     </div>
  69.                     <div class="clear"></div>
  70.                     {% endblock %}
  71.                     {% block contact_form_alerts %}
  72.                         <div class="d-none" id="contact-form-error">
  73.                             {% sw_include '@Storefront/storefront/utilities/alert.html.twig' with {
  74.                                 type: "danger",
  75.                                 content: "wexo-cms.elements.simple-contact-form.error"|trans
  76.                             } %}
  77.                         </div>
  78.                     {% endblock %}
  79.                 </div>
  80.             </div>
  81.         </div>
  82.         <script>
  83.             function submitContactForm(elm) {
  84.                 let placeholder = "placeholder";
  85.                 let mail = document.getElementById("form-email");
  86.                 let validate = document.getElementById("contactFormValidator");
  87.                 if (elm && document.getElementById("form-email")) {
  88.                     let mailData = {};
  89.                     mailData.salutationId = "{{ config('WexoShoppingExperiences.config.salutationId') }}"
  90.                     if (!mailData.salutationId || mailData.salutationId == '') {
  91.                         //SalutationId for value not_specified
  92.                         mailData.salutationId = "07ed1e41549f40999a8f8d3522126a57";
  93.                     }
  94.                     document.getElementById("form-firstName") ? mailData.firstName = document.getElementById("form-firstName").value : placeholder;
  95.                     mailData.lastName = placeholder;
  96.                     mailData.cvr = placeholder;
  97.                     mailData.email = mail.value;
  98.                     mailData.phone = placeholder;
  99.                     mailData.subject = placeholder;
  100.                     document.getElementById("form-comment") ? mailData.comment = document.getElementById("form-comment").value : placeholder;
  101.                     mailData.slotId = "{{ element.id }}";
  102.                     let showError = function () {
  103.                         let error = document.getElementById("contact-form-error");
  104.                         let classes = error.className;
  105.                         error.classList.remove("d-none");
  106.                         setTimeout(() => {
  107.                             error.style.opacity = 1;
  108.                         }, 1);
  109.                         setTimeout(() => {
  110.                             if (error) {
  111.                                 error.className = classes;
  112.                                 error.style.opacity = 0;
  113.                             }
  114.                         }, 4000);
  115.                     }
  116.                     if (mail.value.length > 0 && validate.value === '') {
  117.                         let contactFormCall = Wtheme.api.post("/store-api/contact-form", JSON.stringify(mailData), function () {
  118.                             if (contactFormCall.status === 200 || contactFormCall.status === 204 || contactFormCall.status === 202) {
  119.                                 document.getElementById("simpleContactForm").innerHTML = "<div class='confirm-message'>{{ confirmationText|raw }}</div>";
  120.                             } else {
  121.                                 showError();
  122.                             }
  123.                         });
  124.                     } else {
  125.                         showError();
  126.                     }
  127.                 }
  128.             }
  129.         </script>
  130.     </div>
  131. {% endblock %}