0

I have a form that i made with nodemailer and it works on desktop and android devices but it doesnt work on ios.

I have no idea what i might be doing wrong.

The website is https://ozixmedia.com

HTML:

<section id="contact" class="wow fadeIn">
<h1 id="target" class="">Envianos Tu Consulta</h1>
    <div class="row container">
<form method="POST" class="col s12">
  <div class="row">
    <div class="input-field col s6">
      <input id="name" type="text" class="validate" name="name">
      <label for="name">Nombre</label>
    </div>
      <div class="input-field col s6">
      <input id="last_name" type="text" class="validate" name="name">
      <label for="last_name">Apellido</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s6">
      <input id="email" type="email" class="validate" name="name">
      <label for="email">Email</label>
    </div>
      <div class="input-field col s6">
      <input id="phone" type="number" class="validate" name="name">
      <label for="phone">Teléfono</label>
    </div>
  </div>
    <div class="row">
      <div class="input-field col s12">
        <textarea id="message" class="materialize-textarea" data-length="120" name="name"></textarea>
        <label for="message">Consulta</label>
      </div>
    </div>
    <input type = "submit" value = "Enviar" class="btn-large-light">
</form>
</div>

</section>

My JS code:

$('form').on('submit', e => {
  e.preventDefault();

  const email = $('#email').val().trim();
  const name = $('#name').val().trim();
  const last_name = $('#last_name').val().trim();
  const phone = $('#phone').val().trim();
  const text = $('#message').val().trim();

  const data = {
    email,
    name,
    last_name,
      phone,
    text
  };

  $.post('/email', data, () => {
    console.log('Server recieved our data')
  });
  window.location.replace('/redirect')
});
Alon Eitan
  • 11,997
  • 8
  • 49
  • 58
Nicolas
  • 63
  • 6
  • what happens when you run the code on ios? Have you tried testing on Safari incase you have a Mac? – Fernando B Aug 16 '19 at 18:30
  • When i submit the form the website redirects me to /redirect, but the email is not sent. I didnt try on mac, but i tried on iphone with safari and chrome – Nicolas Aug 16 '19 at 18:33
  • I've already found the problem. The location.replace must be inside the $.post callback. – Nicolas Aug 19 '19 at 23:00

1 Answers1

0

For ios that runs on Safari try changing const to var to see if that might work.

As mentioned here it's an ES2016 issue

$('form').on('submit', e => {
  e.preventDefault();

  var email = $('#email').val().trim();
  var name = $('#name').val().trim();
  var last_name = $('#last_name').val().trim();
  var phone = $('#phone').val().trim();
  var text = $('#message').val().trim();

  var data = {
    email,
    name,
    last_name,
      phone,
    text
  };

  $.post('/email', data, () => {
    console.log('Server recieved our data')
  });
  window.location.replace('/redirect')
});
Fernando B
  • 864
  • 2
  • 12
  • 27