Say, I have something like this
function submitform() {
var data = JSON.stringify({
"userdata": $('#user_data').val()
})
$('<input type="hidden" name="json"/>').val(data).appendTo('#myform');
$("#myform").submit();
}
Now on the Server side, I've tried:
json_decode($_POST['json']);
json_decode($_POST['json'], true);
json_decode(htmlspecialchars_decode($_POST['json']), true);
All of these return NULL value when I do a var_dump on the page.
I am not submitting the form via ajax, and I do not want to use application/json to submit the form because there are other fields in the form that need to be submitted the normal form submission way.
How can I do this?? Just need to send json to php on form submission.
submitform()? What's theactionattribute set to on theformelement? Also note that your method of appending the user_id to the URL is really not secure in any way.methodused on your form? I know, it could be obvious, but if its not filled in you will need to look inside$_GET...method="post"on form.databefore you submit. Does it have a value?