Hello!

There is a feedback form on the site. If the required fields are not filled in, then it writes an error (works), but the sending message never appears (if the required fields are filled in).

What could be the error? Site on UMI. Thank!

Code:

<xsl:template match="udata[@form_id]" mode="content-content-contacts-form"> <div class="form_block"> <p class="top_text">Ваше сообщение успешно отправлено!</p> <form action="/webforms/dispatch/" method="POST"> <xsl:apply-templates select="current()//field[@name = 'contacts_name']" mode="content-content-contacts-form-field"> <xsl:with-param name="id">name</xsl:with-param> </xsl:apply-templates> <xsl:apply-templates select="current()//field[@name = 'contacts_email']" mode="content-content-contacts-form-field"> <xsl:with-param name="id">email</xsl:with-param> </xsl:apply-templates> <xsl:apply-templates select="current()//field[@name = 'contacts_phone']" mode="content-content-contacts-form-field" /> <xsl:apply-templates select="current()//field[@name = 'contacts_message']" mode="content-content-contacts-form-field-message" /> <xsl:apply-templates select="current()" mode="webforms-system-fields" /> <a class="send_data" href="javascript:void(0)">Отправить</a> </form> </div> </xsl:template> 

Js:

 // Check empty inputs $('.send_data').on('click', function(event) { event.preventDefault(); if ( !$('#name').val() && !$('#email').val() ) { $('#name, #email').addClass('empty'); $('.top_text').fadeIn().addClass('red').text('Пожалуйста, заполните все необходимые поля'); } else if ( !$('#name').val() ) { $('#name').addClass('empty'); $('.top_text').fadeIn().addClass('red').text('Пожалуйста, заполните все необходимые поля'); } else if ( !$('#email').val() ) { $('#email').addClass('empty'); $('.top_text').fadeIn().addClass('red').text('Пожалуйста, заполните все необходимые поля'); } else { var $form = $(this).parents('form'); $.ajax($form.attr('action'), { data: $form.serialize(), success: function() { $('.top_text').fadeIn().removeClass('red').text('Ваше сообщение успешно отправлено!'); } }); } // $('.req').each(function() { // if ( !$(this).val() ) { // $(this).addClass('empty'); // $('.top_text').fadeIn().addClass('red').text('Пожалуйста, заполните все необходимые поля'); // } // else { // $('.top_text').fadeIn().removeClass('red').text('Ваше сообщение успешно отправлено!'); // } // }); }); $('.req').focusin(function(event) { $(this).removeClass('empty'); }); ////// }); 

  • Add the error handler to ajax and output an error to the console, then it will become clear why it does not work - Ivan Frolov
  • How to do it? - Anton Vlasov
  • Here is the link - Ivan Frolov
  • db.tt/6ZOEzi1x - Anton Vlasov
  • so try it out - Ivan Frolov

0