craftcms / guest-entries

Accept anonymous entry submissions with Craft.
MIT License
106 stars 26 forks source link

`Validate?` is set to off, but still receiving validation error when submitting via axios #51

Open kblizeck opened 4 years ago

kblizeck commented 4 years ago

Hi there! I am submitting a Guest Entry form via axios, and am receiving the following error "Values did not pass validation.". Validate? is set to off in the plugin settings, as I'm doing my own validation via Javascript.

const inputs = selectAll(wrapper, 'input, textarea')
    validateInputs(inputs, () => {
      // Guest Entries plugin is expecting data in FormData format, not json
      const formdata = new FormData();
      inputs.forEach((element) => {
        formdata.append(element.name, element.value);
      });

      axios.post(handler, formdata)
        .then((res) => {
          console.log(res);
          // Show message no matter what, as reviews have to be approved by mods anyway
          showMessage(true)
        })
        .catch(err => console.error(err))
    })
  })

I even tried via axios with a JSON object for the data, and I get the same validation error.

validateInputs(inputs, () => {
      // Guest Entries plugin is expecting data in FormData format, not json
      // const formdata = new FormData();
      // inputs.forEach((element) => {
      //   formdata.append(element.name, element.value);
      // });

      let obj = inputs.reduce((acc, current) => {
        acc[current.name] = current.value
        return acc
      }, {})

      axios({
        method: 'post',
        url: handler,
        data: obj,
        config: { headers: {'Accept': 'application/json' }}
      })
        .then((res) => {
          console.log(res);
          // Show message no matter what, as reviews have to be approved by mods anyway
          showMessage(true)
        })
        .catch(err => console.error(err))
    })
brandonkelly commented 4 years ago

Does the JSON response include an errors key? If so, what is in it?