Ok I'm struggling trying to link up a comments form so it posts comments to my Wordpress CMS.
Here is the HTML from my posts page:
<h1>Leave a Reply ⩤</h1>
<form id="form" method="POST">
<input type="text" name="FIRSTNAME" class="name" placeholder="Enter first name..">
<textarea id="subject" name="subject" placeholder="Write a comment.."></textarea>
<input type="submit" value="Submit" id="">
</form>
</div>
and the JS:
var id = JSON.parse(findQuery("id"));
fetch(`https://www.someurl.com/wp-json/wp/v2/comments`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ post: id, author_name: "X", author_email: "x@gmail.com", content: "test post" }),
})
.then((response) => response.json())
.then((data) => {
console.log(data);
});
}
postComment();
Would massively appreciate any help with this?