Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kblizeck opened this issue Oct 7, 2019 · 1 comment

Comments

@kblizeck
Copy link

kblizeck commented Oct 7, 2019

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))
    })
@kblizeck kblizeck changed the title Validate? is set to off, but still receiving validation error when submitting via axios Validate? is set to off, but still receiving validation error when submitting via axios Oct 7, 2019
@brandonkelly
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants