1

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.

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.