Sending submissions with AJAX

If you don't want to redirect the user after they submit the form or want to add extra validation logic to your form, you might want to consider using JavaScript to submit. With Getform, you can send your form data with AJAX. Here's an example code block you can use:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

<script>
   $(function(){
       $("#ajaxForm").submit(function(e){
           e.preventDefault();
           var action = $(this).attr("action");
           $.ajax({
               type: "POST",
               url: action,
               crossDomain: true,
               data: new FormData(this),
               dataType: "json",
               contentType: 'multipart/form-data',
               processData: false,
               contentType: false,
               success: function(response){
                 if(response.status == "success"){
                   alert("We received your submission, thank you!");
                 }else{
                   alert("An error occured.");
               }
             }
           });
         });
       });

</script>

Note: If you want to get your responses in JSON form, you need to add dataType: "json" , it sets Accept Http Header to application/json

After that you can add class="ajaxForm" to your HTML form to finish the setup like this:

<form class="ajaxForm" action="https://getform.io/f/{your-endpoint}" method="POST">

    <input type="text" name="name" id=”name”>
    <input type="email" name="email" id=”email”>
    <button type="submit">Send</button>

</form>

That's it! You can now send your form submissions using AJAX.