Welcome to mirror list, hosted at ThFree Co, Russian Federation.

contact.js « js « assets « static - github.com/aerohub/hugo-identity-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb2d3ad1ae341cfef32e1121abeab6000ff50d48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Initial form validation
$(document).ready(function() {
  $.validate({
    modules : 'html5, toggleDisabled'
  });
});

// Revalidate on change
$('form[id=contactForm]').change(function() {
  $.validate({
    modules : 'html5, toggleDisabled'
  });
});

// Async contact form
$('form[id=contactForm]').submit(function(){
  $('form[id=contactForm] #success').hide();
  $('form[id=contactForm] #error').hide();

  // AJAX POST, with contact form data serialized, which expects a JSON response
  // Datatype must be set to 'json' to use formspree.io
  $.post($(this).attr('action'), $(this).serialize(), function(){
      $('form[id=contactForm] #success').show();
    }, 'json').fail(function(){
      $('form[id=contactForm] #error').show();
  });
  return false;
});

// Callback function for captcha
function onSubmit(token) {
  if (!token) {
     return;
  }
  $('form[id=contactForm]').submit();
}