Please check out our new documentation for the latest updated information on this topic.

How to submit your form with AJAX

If you want more control over your FormKeep form, you may want to consider using JavaScript to submit. This may be a good idea if you are already using a JavaScript framework, you want to add validation logic, or you don't want to redirect the user after they submit the form.

You can submit to FormKeep using a standard AJAX request. To ensure the request does not cause a redirect, be sure to set the Accept header to application/javascript.

Given the following form:


<form id="newsletter-signup" action="https://formkeep.com/f/exampletoken" method="POST" accept-charset="UTF-8">
  <input type="hidden" name="utf8" value="✓">
  <input name="email" type="email">
  <input value="Submit" type="submit">
</form>

Here's an example of how to submit a form with jQuery:


$(function() {
  $('#newsletter-signup').submit(function(event) {
    event.preventDefault();

    var formEl = $(this);
    var submitButton = $('input[type=submit]', formEl);

    $.ajax({
      type: 'POST',
      url: formEl.prop('action'),
      accept: {
        javascript: 'application/javascript'
      },
      data: formEl.serialize(),
      beforeSend: function() {
        submitButton.prop('disabled', 'disabled');
      }
    }).done(function(data) {
      submitButton.prop('disabled', false);
    });
  });
});

That's it! Why not get started now?

Looking for something else?

Email us