• Hey, really hoping someone can help me out here. I’m trying to post a form via the REST API and seem to have everything working in terms of communicating the post request. However, it always returns validation failure. Here is the code.

    handleSubmission = async (e) => {
        e.preventDefault();
    
        var myHeaders = new Headers();
        myHeaders.append("Content-Type", "application/json");
    
        var formdata = new FormData();
        formdata.append("some-name:", this.state.fullname);
        formdata.append("some-email:", this.state.email);
        formdata.append("your-enquiry:", this.state.enquiry);
        formdata.append("your-message:", this.state.message);
    
        var requestOptions = {
          method: 'POST',
          headers: myHeaders,
          body: JSON.stringify(formdata),
          redirect: 'follow'
        };
    
        await fetch("https://www.mycoolsite.com/wp-json/contact-form-7/v1/contact-forms/2090/feedback", requestOptions)
          .then(response => response.json())
          .then(result => console.log(result))
          .catch(error => console.log('error', error));
      }
    

    The formData is definitely not empty. It just doesn’t seem to like the format or something. Here is the response

    
    into: "#"
    invalid_fields: Array(2)
    0: {into: 'span.wpcf7-form-control-wrap.some-name', message: 'The field is required.', idref: null, error_id: '-ve-some-name'}
    1: {into: 'span.wpcf7-form-control-wrap.some-email', message: 'The field is required.', idref: null, error_id: '-ve-some-email'}
    length: 2
    <a href="https://codex.www.ads-software.com/Prototype">Prototype</a>: Array(0)
    message: "One or more fields have an error. Please check and try again."
    posted_data_hash: ""
    status: "validation_failed"

    `

    Would really appreciate any help with this one. Thank you in advance.

    • This topic was modified 3 years, 2 months ago by wpwench.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Validation failure’ is closed to new replies.