is form enctype "application/json" available?
Asked Answered
G

3

30

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?

Gorgerin answered 24/6, 2016 at 15:36 Comment(0)
T
28

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.

Tristan answered 24/6, 2016 at 15:49 Comment(0)
F
2

FYI.. there's a hacky way to mimic this functionality using javascript. Seem my library here: https://github.com/keithhackbarth/submitAsJSON

Fennec answered 18/4, 2018 at 4:59 Comment(0)
E
0

as deceze answered, this specification is no longer in active maintenance, and I found it very sad, now days most API's use JSON and no one use Html Forms as originally designed for HTML 1.0 anymore, so adding this feature could eliminate virtually millions similar lines of code out there and make a modern browser able to directly interact with modern services natively, without single line of code!

maybe I'm a bit greedy here but it could be possible get a complete modern application running without any code by also allow PUT and DELETE for the form method attribute and find a solution similar to 'target' for frames to allow direct JSON responses.

adding that could also potentially unlock the vision of WEB 2.0 where services could be easily integrated in a very simple & straight forward way without complicated code to orchestrate it.

Is it possible to bring this draft live again? it's 9 years after the fact but JSON become extremely popular since.

Equation answered 24/7 at 18:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.