Answers.Body: <p>I shall answer my own question.</p>
  
  <p>The issue was because I was logged in as admin in another browser tab. I was not receiving the "Unauthorized" response from craft. Just the 404. By testing in an incognito window I was able to see I was receiving an unauthorized response from craft which led me to the problem. Which was the sectionId for that particular form was incorrect. SectionId on second form should have been 2 not 4.</p>
  
  <p>Hope this helps anyone else having a similar problem.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-22T22:20:18.657Z
Answers.LastActivityDate: 2017-02-22T22:20:18.657Z
Answers.UserDisplayName: Brendan
Body: <p>I am using the guestentries plugin to create two different section entries. I have two similar html forms on the same front end page. They both use the jquery validate plugin before submiting via ajax. The first form for sectionId(3) does some stripe token generation before submitting to the plugin to submit the payment and create the entry. This is working fine.</p>
  
  <p>The second form doesn't do any stripe calls and is using very much the same jquery ajax call to submit to a sectionId(4). This ajax submission is always returning a 404 and doesn't get to the guestEntries plugin so it seems craft isn't handling this submission like it should?</p>
  
  <p><strong>Succesful request/response</strong></p>
  
  <p>[Code]</p>
  
  <pre><code>    var formData = $("form[name='playerForm']").serialize();
      $.post('/', formData , function(response) {
        if (response.success) {
        //On Submit Success
        $("form[name='playerForm'] input[type='text'],select").val("");
  
        $('#playerForm').slideUp();
  
        $('#registered_user_name').text(response.title);
        $('#myModal').modal('show');
        $('#submitLoader').replaceWith('&lt;input type="submit" class="submit" id="playerSubmit" value="Continue" /&gt;');
  
      }else{
        console.log(response);
      }
    });
  </code></pre>
  
  <p>[Form Data]</p>
  
  <pre><code>CRAFT_CSRF_TOKEN:kv8AfC8Odbhq7OFX6eUhJEi~lm2LqTgmubFer48b|4af89cb67bc43b2efb63a00273e638708f85f5ab
  action:guestEntries/saveEntry
  sectionId:3
  fields[firstName]:Test
  fields[lastName]:Guy
  fields[homeTown]:Town
  fields[phoneNumber]:234 342 2343
  fields[companyEducationalInstitution]:Test Company
  fields[averageScore]:81-90
  fields[yearsInTheTournament]:1
  token:tok_19pQkWKdnBUCmelLfVYMRhaF
  fields[email]:test@test.com
  </code></pre>
  
  <p><strong>Failed request/response</strong></p>
  
  <p>[Code]</p>
  
  <pre><code>var data = $("form[name='sponsorForm']").serialize();
  
  $.post('/', data, function (response) {
    if (response &amp;&amp; response.success) {
      console.log(response);
    } else {
      console.log(response);
    }
    $('#submitLoader').replaceWith('&lt;input type="submit" class="submit" id="sponsorSubmit" value="Submit" /&gt;');
  });
  </code></pre>
  
  <p>[Form Data]</p>
  
  <pre><code>CRAFT_CSRF_TOKEN:kv8AfC8Odbhq7OFX6eUhJEi~lm2LqTgmubFer48b|4af89cb67bc43b2efb63a00273e638708f85f5ab
  action:guestEntries/saveEntry
  sectionId:4
  fields[sponsorFirstName]:Test
  fields[sponsorLastName]:Guy
  fields[sponsorPhoneNumber]:252 356 5626
  fields[company]:Test Company
  </code></pre>
  
  <p>I've compared the request headers and they are identical so I don't think it's an ajax header problem. Not sure why first form would work and second would fail. Any help is greatly appreciated.</p>
  
Tags: <ajax><guest-entries><plugin-guestentries>
Title: Guest Entries - Two ajax forms for different section entries. Receiving 404 only on second form?
ThreadText: # Guest Entries - Two ajax forms for different section entries. Receiving 404 only on second form?
  
  (Asked by: username_0 on 2017-02-21)
  
  I am using the guestentries plugin to create two different section entries. I have two similar html forms on the same front end page. They both use the jquery validate plugin before submiting via ajax. The first form for sectionId(3) does some stripe token generation before submitting to the plugin to submit the payment and create the entry. This is working fine.
  
  The second form doesn't do any stripe calls and is using very much the same jquery ajax call to submit to a sectionId(4). This ajax submission is always returning a 404 and doesn't get to the guestEntries plugin so it seems craft isn't handling this submission like it should?
  
  **Succesful request/response**
  
  [Code]
  
  ```
      var formData = $("form[name='playerForm']").serialize();
      $.post('/', formData , function(response) {
        if (response.success) {
        //On Submit Success
        $("form[name='playerForm'] input[type='text'],select").val("");
  
        $('#playerForm').slideUp();
  
        $('#registered_user_name').text(response.title);
        $('#myModal').modal('show');
        $('#submitLoader').replaceWith('<input type="submit" class="submit" id="playerSubmit" value="Continue" />');
  
      }else{
        console.log(response);
      }
    });
  
  ```
  
  [Form Data]
  
  ```
  CRAFT_CSRF_TOKEN:kv8AfC8Odbhq7OFX6eUhJEi~lm2LqTgmubFer48b|4af89cb67bc43b2efb63a00273e638708f85f5ab
  action:guestEntries/saveEntry
  sectionId:3
  fields[firstName]:Test
  fields[lastName]:Guy
  fields[homeTown]:Town
  fields[phoneNumber]:234 342 2343
  fields[companyEducationalInstitution]:Test Company
  fields[averageScore]:81-90
  fields[yearsInTheTournament]:1
  token:tok_19pQkWKdnBUCmelLfVYMRhaF
  fields[email]:test@test.com
  
  ```
  
  **Failed request/response**
  
  [Code]
  
  ```
  var data = $("form[name='sponsorForm']").serialize();
  
  $.post('/', data, function (response) {
    if (response && response.success) {
      console.log(response);
    } else {
      console.log(response);
    }
    $('#submitLoader').replaceWith('<input type="submit" class="submit" id="sponsorSubmit" value="Submit" />');
  });
  
  ```
  
  [Form Data]
  
  ```
  CRAFT_CSRF_TOKEN:kv8AfC8Odbhq7OFX6eUhJEi~lm2LqTgmubFer48b|4af89cb67bc43b2efb63a00273e638708f85f5ab
  action:guestEntries/saveEntry
  sectionId:4
  fields[sponsorFirstName]:Test
  fields[sponsorLastName]:Guy
  fields[sponsorPhoneNumber]:252 356 5626
  fields[company]:Test Company
  
  ```
  
  I've compared the request headers and they are identical so I don't think it's an ajax header problem. Not sure why first form would work and second would fail. Any help is greatly appreciated.
  
  **Tags:** ajax, guest-entries, plugin-guestentries
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-02-22. Score: 1 | Accepted answer
  
  I shall answer my own question.
  
  The issue was because I was logged in as admin in another browser tab. I was not receiving the "Unauthorized" response from craft. Just the 404. By testing in an incognito window I was able to see I was receiving an unauthorized response from craft which led me to the problem. Which was the sectionId for that particular form was incorrect. SectionId on second form should have been 2 not 4.
  
  Hope this helps anyone else having a similar problem.
  
  
  ---
  
  