I have a string that I would like to pass from JS to PHP via a hidden input, but the POST form does not return anything at arrival (I checked it with a var_dump($_POST)), which never happened to me at all.
Here is my HTML code:
<form action='' id='hash-form'>
<input type='hidden' id='hash' name='hash'/>
</form>
Here is my JS code for changing the value and submitting:
document.getElementById("hash").value = content;
console.log(document.getElementById("hash").value);
document.getElementById("hash-form").submit();
Thanks in advance!
>Solution :
The form lacks of the method attribute, thus it’s GET by default, not post.
Add method="POST" into a form tag.
What is the default form HTTP method?