Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is form enctype "application/json" available?

Tags:

I was reading this w3c document about post JSON data with html form, and trying to test it.

my test form is as follows:

 <form action="postjson.php" method="POST" enctype="application/json">     <input type="hidden" name="touser" value="shenkwen" />     <input type="hidden" name="msgtype" value="text" />     <input type="hidden" name="agentid" value="23" />     <input type="hidden" name="text[content]" value="test message" />     <input type='submit' value="submit" />   </form> 

and content for postjson.php

<?php var_dump($_POST);  

I was expecting the value of $_POST being a JSON string, however, it is just a normal PHP object:

array(4) { ["touser"]=> string(8) "shenkwen" ["msgtype"]=> string(4) "text" ["agentid"]=> string(2) "23" ["text"]=> array(1) { ["content"]=> string(33) "test message" } } 

I tried removing the enctype attribute and the output is exactly the same. Then I went back to the document page and noticed that it says something indicating this standard may not be in effect.

So this is also a question about how to use W3C website, it seems to me some pages on it are just drafts. So is this page a draft? When I read pages on w3c how do I tell whether it is a draft or it is a working standard? And finally and most importantly, is enctype='application/json' working or not?

like image 436
shenkwen Avatar asked Jun 24 '16 15:06

shenkwen


People also ask

Can we send JSON in form data?

Using the JSON. stringify() method then format the plain form data as JSON. Specify the HTTP request method as POST and using the header field of the Fetch API specify that you are sending a JSON body request and accepting JSON responses back. Then set the request body as JSON created from the form fields.

How do I save HTML form data to JSON file?

stringify($("#emails_form"). serializeArray()); If you want to store formData in a JSON file, you need to post it to the server (e.g. per AJAX) and save it. But in that case, you can simply post the form und convert it to JSON on the server itself.


1 Answers

The W3C publishes many drafts and proposals which are then discussed within the community at large. If a draft makes it to the stage where it's generally considered useful, browser vendors will/may start implementing it. The draft then typically advances to a "recommendation" stage, meaning the W3C officially recommends that browsers implement the technology as specified; but of course they can't twist anyone's arm to actually do so.

Each document will say at its top what its current status is, and http://www.w3.org/TR/ lists all current documents and their status. The one you picked is listed as "obsolete" and "retired" on that page and has a ginormous banner at its top saying:

Beware. This specification is no longer in active maintenance and the HTML Working Group does not intend to maintain it further.

So, no, probably no browser is currently implementing it.

To track the real-world availability of a feature you need to look to 3rd party resources like https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-enctype and http://caniuse.com.

like image 74
deceze Avatar answered Sep 25 '22 12:09

deceze