<p>First I want to say thank you to the support staff at Sprout for helping me figure out my error. </p>

<p>I have the default install settings/configuration for a Sprout form. Spam protection was enabled in my case and that's what was causing the 302.</p>

<p>If I want to have spam protection enabled, I need to have this inside my <code>&lt;form&gt;</code> tags:</p>

<pre><code>{% hook 'sproutForms.modifyForm' %}
</code></pre>

<p>So my form looks like this now:</p>

<pre><code>&lt;form id="contact-form" method="post" class="main-form" accept-charset="utf-8"&gt;
    &lt;fieldset&gt;
        {% hook 'sproutForms.modifyForm' %}
        {{ csrfInput() }}
        &lt;input type="hidden" name="action" value="sprout-forms/entries/save-entry"&gt;
        &lt;input type="hidden" name="redirect" value="{{ form.redirectUri|hash }}"&gt;
        &lt;input type="hidden" name="handle" value="{{ form.handle }}"&gt;
    &lt;/fieldset&gt;

    &lt;fieldset&gt;
        {# Get the full name field. #}
        {% set fullName = form.getField('fullName') %}

        ...
    &lt;/fieldset&gt;
&lt;/form&gt;
</code></pre>

<p>I'm getting a 200 response back and the entry is getting created!</p>

CC BY-SA 4.0
2018-09-16T01:05:39.680Z
2018-09-16T01:05:39.680Z
Damon
<p>I am using Sprout Forms on a Craft 3 site and trying to submit my form via ajax.</p>

<p>I've been able to do this many times in Craft 2, but not having much luck with 3 (yet). <a href="https://sprout.barrelstrengthdesign.com/docs/forms/submitting-a-form-via-ajax.html" rel="nofollow noreferrer">The docs</a> look mainly for Craft 2 - is there a better way to find examples for Craft 3?</p>

<p>Here is what the headers look like that I am sending:</p>

<pre><code>CRAFT_CSRF_TOKEN: &lt;huge string hash&gt;
action: sprout-forms/entries/save-entry
redirect: &lt;long redirect hash&gt;
handle: contact
fields[fullName]: Damon
fields[email]: name@test.com
fields[phone]: 211-111-1111
fields[message]: Hello.
</code></pre>

<p>I am always getting a 302 response back - without any error or other indication of what might be missing. If I remove the <code>handle</code> field, I'll get a 400 error, so I know I'm hitting the correct method.</p>

<p><code>Status Code: 302 Found</code></p>

<p>Here is what my js looks like:</p>

<pre><code>$.ajax({
    type: 'post',
    contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
    cache: false,
    data: $('#contact-form').serialize(),
    url: $('input[name=action]').val(),
    processData: false,
    dataType: 'json',
    timeout: 50000
}).done(function (response) {
    console.log(response);  // nothing.
}).fail(function (error) {
    // Total fail.
});
</code></pre>

<p>Here is what I am including in my form that is Craft/Sprout specific. </p>

<pre><code>{{ csrfInput() }}
&lt;input type="hidden" name="action" value="sprout-forms/entries/save-entry"&gt;
&lt;input type="hidden" name="redirect" value="{{ form.redirectUri|hash }}"&gt;
&lt;input type="hidden" name="handle" value="{{ form.handle }}"&gt;
</code></pre>

<p>Thank you for any suggestions!</p>

<craft3><plugin-sproutforms>
Why is Sprout Forms returning 302 for ajax requests?
# Why is Sprout Forms returning 302 for ajax requests?

(Asked by: username_0 on 2018-09-06)

I am using Sprout Forms on a Craft 3 site and trying to submit my form via ajax.
I've been able to do this many times in Craft 2, but not having much luck with 3 (yet). The docs look mainly for Craft 2 - is there a better way to find examples for Craft 3?
Here is what the headers look like that I am sending:
CRAFT_CSRF_TOKEN: 
action: sprout-forms/entries/save-entry
redirect: 
handle: contact
fields[fullName]: Damon
fields[email]: name@test.com
fields[phone]: 211-111-1111
fields[message]: Hello.

I am always getting a 302 response back - without any error or other indication of what might be missing. If I remove the handle field, I'll get a 400 error, so I know I'm hitting the correct method.
Status Code: 302 Found
Here is what my js looks like:
$.ajax({
    type: 'post',
    contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
    cache: false,
    data: $('#contact-form').serialize(),
    url: $('input[name=action]').val(),
    processData: false,
    dataType: 'json',
    timeout: 50000
}).done(function (response) {
    console.log(response);  // nothing.
}).fail(function (error) {
    // Total fail.
});

Here is what I am including in my form that is Craft/Sprout specific. 
{{ csrfInput() }}




Thank you for any suggestions!

**Tags:** craft3, plugin-sproutforms

---

## 1 answers

### Answer by username_0 on 2018-09-16. Score: 2 | Accepted answer

First I want to say thank you to the support staff at Sprout for helping me figure out my error. 
I have the default install settings/configuration for a Sprout form. Spam protection was enabled in my case and that's what was causing the 302.
If I want to have spam protection enabled, I need to have this inside my  tags:
{% hook 'sproutForms.modifyForm' %}

So my form looks like this now:

    
        {% hook 'sproutForms.modifyForm' %}
        {{ csrfInput() }}
        
        
        
    

    
        {# Get the full name field. #}
        {% set fullName = form.getField('fullName') %}

        ...
    


I'm getting a 200 response back and the entry is getting created!


---

