Live data from Hacker News

W3C HTML JSON form submission

w3.org

91–100 of 103 posts

Re: W3C HTML JSON form submission

#91
post #84

Wow, W3C at it's best again. Non-modular, non-negotiable, JSON it is, take it or leave it. Well fuck you W3C. Base64 encoded files? Seriously? What if my app workes better with msgpack encoded forms? Or with XML encoded? So you're going to support one particular serialization format, quite a horrible one, but that's subjective and that's the whole point. Every app has different needs and you should spec. out a system…

How would you deal with rendering arbitrary form encodings in the browser? A proposal adding support for form submission of arbitrary encodings could be valid, but it'd have to just be a single form input with the data included verbatim. This proposal allows regular HTML forms with multiple input elements, but submitting over JSON. I can't see how you could define that for arbitrary encodings without first defining h…

Eg: By referencing an encoder function using the standard on* attribute. Could be called onbeforesubmit=encodeMsgpack. This function would take a JS object, generated according to the W3C's JSON form spec, and return a pair of [string, arraybuffer]. String being the MIME content type, and arraybuffer containing the request body.

Re: W3C HTML JSON form submission

#92
post #42

Let me say first of all that I'm glad they're working on standardizing this. When making REST APIs, I find HTML form scaffolds incredibly useful, but it means that you probably have to accept both JSON (because JSON is reasonable) and occasional form-encoding (because forms), leading to subtle incompatibilities. Or you have to disregard HTML and turn your forms into JavaScript things that submit JSON. Either way, the…

Think that's fair point, yup. Very easy to do unintentionally, and it's non-intuitive that it'll suddenly change the return type. It's not clear if this style is really necessary. Why not just use the indexed syntax in this case? I guess it may be the authors intention to mirror form encoded submissions, that would send all of these values to the server. I'd suggest raising the point on the issue tracker so that it a…

Well, the safe way would be to mirror the current form spec and treat everything as arrays of strings by default.

    
      
      
      
      
    


    {
      "fruit": ["apple"],
      "bottle-on-wall": ["1", "2", "3"]
    }
Then add attributes to explicitly give the structure. Since this is a browser spec we can add attributes. Here's the same form but with some attributes giving the explicit encoding.

    
      
      
      
      
    

    {
      "fruit": "apple",
      "bottle-on-wall": [1, 2, 3]
    }
Dynamically varying JSON structures by form names and number of form elements is definitely going to be a source of bugs and security problems.

Re: W3C HTML JSON form submission

#93

Earlier quoted context omitted.

I don't think multiple fields with the same name is designed to be a normal mode of operation. If you actually want an array, use the [] suffix. But if you have a bug which produces a form with multiple fields with the same name, what should it do? I can think of two strategies: last one wins and the proposal. Both are probably going to lead to things going wrong in the backend. At least with the proposal you: A) can…

do any server-side environments currently present an array/array-like structure from request parameters with duplicate names (and specifically without any kind of array indicator, like name[] in php requests for example)?

jersey[0], the reference implementation of JAX-RS[1] does this if you specify an incoming query string parameter as a `List`

[0] https://jersey.java.net/ [1] https://jax-rs-spec.java.net/

Re: W3C HTML JSON form submission

#94

I'm not sure whether to be heartened or concerned that the W3C is referencing the doge meme in its specifications... see Example 6.

Concerned. Memes are in-group signalling one notch above the crudest kind such as football chants, a few notches below the more sophisticated kind like quoting Shakespeare, but all ultimately with the potential to exclude and confuse - which is definitely the opposite of what a technical spec should be trying to do.

Re: W3C HTML JSON form submission

#95

Earlier quoted context omitted.

Nodes have multiple children. In this case, you can split the 's children into three: a "text node"; a node; and another text node. You'd end up with something like this: { p: [ { text: 'This is' }, { b: { text: 'bold' }}, { text: 'text.'} ] } Not that I don't agree with you -- my suggestion is pretty messy and doesn't even go into how we'd deal with tag attributes -- but it's doable.

This has to be pre-processed somehow, if people don't like writing HTML by hand, consider writing that.

Yeah, and that's not really equivalent HTML either. That's more like:

    

This is bold text.

(which is a lot easier for a machine to parse, at least.)

JSON and YAML are great for what they do: data serialization, but they're just not appropriate choices for text markup. You have to use the right tool for the job.

There was a time when the industry wanted to cram 100% of everything into XML, and that gave us XSLT, XAML, SOAP, etc. We don't want to go back to that, either.

Personally, I'm most fond of an extended Markdown syntax to replace HTML. But I'm not going to hold my breath waiting on web browser vendors to agree on such a syntax, so instead I have my HTTP server do the conversion to HTML for me.

But if you had to force it into JSON, then I would suggest using a different markup for inline elements, eg:

    html
      body
        p: "This is [/italic/] text."
        p: "This is [[google.com => a hyperlink.]]"

Re: W3C HTML JSON form submission

#96
post #84

Wow, W3C at it's best again. Non-modular, non-negotiable, JSON it is, take it or leave it. Well fuck you W3C. Base64 encoded files? Seriously? What if my app workes better with msgpack encoded forms? Or with XML encoded? So you're going to support one particular serialization format, quite a horrible one, but that's subjective and that's the whole point. Every app has different needs and you should spec. out a system…

I think the spec you are looking for is JavaScript.

Re: W3C HTML JSON form submission

#97
post #24

Earlier quoted context omitted.

It lets you comment out a line without having to remove the trailing comma from the previous line. That'd be useful if JSON had comments. I've seen people do this in the SELECT portion of SQL queries too. Personally, I hate this.

> It lets you comment out a line without having to remove the trailing comma from the previous line That would only be an advantage above comma at the end on the last line. It really only moves the problem from the last line to the first one. Now you can't comment out the first line without removing a comma...

In the comma-first method, adding a new element at the end produces a one mine diff. But when doing comma-last method, then adding a new element to the list gives a two line diff.

It can make resolving merges just a little bit easier.

Re: W3C HTML JSON form submission

#98
post #94

I'm not sure whether to be heartened or concerned that the W3C is referencing the doge meme in its specifications... see Example 6.

Concerned. Memes are in-group signalling one notch above the crudest kind such as football chants, a few notches below the more sophisticated kind like quoting Shakespeare, but all ultimately with the potential to exclude and confuse - which is definitely the opposite of what a technical spec should be trying to do.

I don't see why would this exclude or confuse. It's essentially an in-joke, and shouldn't affect anyone reading the spec who is unaware of the meme.

I'm not a fan, but I don't think we should make it out to be more than it really is.

Re: W3C HTML JSON form submission

#100
post #91

Earlier quoted context omitted.

How would you deal with rendering arbitrary form encodings in the browser? A proposal adding support for form submission of arbitrary encodings could be valid, but it'd have to just be a single form input with the data included verbatim. This proposal allows regular HTML forms with multiple input elements, but submitting over JSON. I can't see how you could define that for arbitrary encodings without first defining h…

Eg: By referencing an encoder function using the standard on* attribute. Could be called onbeforesubmit=encodeMsgpack. This function would take a JS object, generated according to the W3C's JSON form spec, and return a pair of [string, arraybuffer]. String being the MIME content type, and arraybuffer containing the request body.

If you're going to run custom JS code, why not simply submit it through JS HTTP requests? What have you gained by this new API?
Post reply on HN