1

I'm trying to submit entry data via AJAX (using Guest Entries plugin) following what's written in a similar question, however even though I am not sending the data in JSON format, the data does not seem to want to save and keeps returning a "cannot be blank error" for every field submitted.

{"errors":{"title":["Title cannot be blank."],"add01e":["Email cannot be blank."],"firstName":["First Name cannot be blank."],"lastName":["Last Name cannot be blank."]}}

These are, in reality, are being submitted as can be seen below. What's strange is that the sectionId and action are being processed for the server to respond with the latter list of errors.

Sent Form Data Source:

action=guestEntries%2FsaveEntry&sectionId=14&firstName=asdsa&lastName=dsad&add01e=asd%40sd.com&companyName=asd&redirectUrl=%2Fcontent%2Fdownloads%2Fproducts%2Fstrokepad%2F6pm-strokepad-brochure-a4_web_300115.pdf&title=Download+Request

Sent Form Data Parsed:

action:guestEntries/saveEntry
sectionId:14
firstName:asdsa
lastName:dsad
add01e:asd@sd.com
companyName:asd
redirectUrl:/content/downloads/products/strokepad/6pm-strokepad-brochure-a4_web_300115.pdf
title:Download Request

Other details related to the request:

Request URL:http://craft.dev/
Request Method:POST
Status Code:200 OK

Content-Type:application/x-www-form-urlencoded; charset=UTF-8

JS performing the ajax request:

var formData = $form.serializeArray();
formData.push({name:'title',value:'Download Request'});
$.post('/', formData , function(response) {
    if (response.success) {
      //On Submit Success
    }else{
      alert('An error occurred. Please try again.');
    }
});

Any idea what I might be doing wrong?

Thanks in advance!

  • Added my own answer below – Daniel Paras Mar 14 '15 at 14:43
3

Ok found the solution to this.

All input fields must have the following format fields[handle] - i was just using the handle!

Example:

<input name="fields[firstName]" id="firstName" type="text" placeholder="First name *">

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.