News for hackers. Stuff that matters.
Re:Substituting JavaScript with HTML by linopolus on Saturday October 14, 2017 @03:28PM (#15473755)
Coolest thing is: You can do completely without JS:

    <form action="https://example.com/submit_foo" method="POST">
        <input type="text" name="bar">
        <input type="submit" value="Submit">
    </form>
Browser handles sending, backend handles processing.

Yes, blows my mind too..

Re:Substituting JavaScript with HTML by foxhop on Saturday October 14, 2017 @03:35PM (#15473790)
I was thinking this too. Forms never _needed_ Javascript to post. It's always worked this way. Am I missing something?
Re:Substituting JavaScript with HTML by userbinator on Saturday October 14, 2017 @07:53PM (#15474994)
If I were to guess, it's probably because you learned HTML before JS. Those who learned JS first, or were never exposed fully to HTML, are unlikely to see the simpler solution first, because they're tempted to use JS for everything. An excellent example of the "when all you have is a hammer, everything looks like a nail" principle.
Re:Substituting JavaScript with HTML by Can_Not on Monday October 16, 2017 @09:01AM (#15482858)
The simpler solution, being that it is what it is, can't do everything that the advanced solution can do. So it's another misuse of the hammer and nail quote. This is a good example of 2 hammers that are optimized for 2 different use cases.
Re:Substituting JavaScript with HTML by uuuyyy111 on Sunday October 15, 2017 @05:40PM (#15479457)
Explains node.js to some degree too. Very glad I didn't enter the scene now with what I see in JS development.
Re:Substituting JavaScript with HTML by mscdex on Saturday October 14, 2017 @04:54PM (#15474241)
Alternative HTTP methods (only GET and POST are supported in HTML forms).

Also, there is the setting of HTTP headers which requires JavaScript.

Re:Substituting JavaScript with HTML by eberkund on Saturday October 14, 2017 @05:35PM (#15474442)
I just use a hidden field to handle that.

  <input type="hidden" name="_method" value="PATCH">
Re:Substituting JavaScript with HTML by abritinthebay on Saturday October 14, 2017 @09:02PM (#15475259)
That doesn’t actually handle that however (you’re just telling a server that your get/post intends something else).

The server has to support it.

Re:Substituting JavaScript with HTML by GoToRO on Saturday October 14, 2017 @04:44PM (#15474178)
Form validation.
Re:Substituting JavaScript with HTML by krapp on Saturday October 14, 2017 @05:42PM (#15474491)
Form validation doesn't need to be done in Javascript. I'd argue that it shouldn't ever be done in Javascript, because that means implicitly trusting the client, which is always a bad idea.

Since any sane application revalidates the response on the server anyway, client side validation is just a gimmick, it's not necessary.

Re:Substituting JavaScript with HTML by dwaltrip on Saturday October 14, 2017 @06:16PM (#15474633)
It creates a better user experience.

We create a worse user experience by waiting until the form is submitted to inform the user of some silly error.

For some applications, the difference isn't that big, but for many it brings a significant improvement.

Is it possible to create crappy client side validation? E.g. not letting the user temporarily input invalid data while filling out the form, or displaying over-the-top red error indicators everywhere as soon as a single mistake is made, etc... Definitely. But let's not throw the baby out with the bathwater.

The backend should never trust the client, of course. That is a separate goal of the application, however.

Re:Substituting JavaScript with HTML by Spivak on Saturday October 14, 2017 @05:56PM (#15474557)
Validation on the client is to catch user mistakes, validation on the server is to catch malicious actors.
Re:Substituting JavaScript with HTML by Kuraj on Saturday October 14, 2017 @06:52PM (#15474757)
> I'd argue that it shouldn't ever be done in Javascript, because that means implicitly trusting the client, which is always a bad idea.

It absolutely shouldn't be done in Javascript only.

Re:Substituting JavaScript with HTML by untog on Saturday October 14, 2017 @07:00PM (#15474792)
> client side validation is just a gimmick

Server side validation requires a whole page round trip. The user will have to wait, lose their scroll position... you can't rely on client side validation only, but neither is it a gimmick.

Re:Substituting JavaScript with HTML by studio_monolith on Saturday October 14, 2017 @11:42PM (#15475766)
What is ajax
Re:Substituting JavaScript with HTML by Zecc on Sunday October 15, 2017 @12:25AM (#15475885)
> What is ajax

Server-side validation relying on JavaScript. You still have to wait for the server to respond, and now you need to implement UI to tell the user something is happening in the background. But at least you can start proactively validating before the user actually submits the form, so there's that.

Re:Substituting JavaScript with HTML by linopolus on Sunday October 15, 2017 @01:29AM (#15476045)
In special cases, maybe. Basic validation (Email looks like email, number contains no text...) is done by the browser automatically if you use semantically correct <input> types: http://diveintohtml5.info/forms.html#validation
Re:Substituting JavaScript with HTML by obilgic on Saturday October 14, 2017 @04:50PM (#15474216)
Plus dynamic fields, options
Re:Substituting JavaScript with HTML by whipoodle on Sunday October 15, 2017 @05:27AM (#15476485)
CSRF protection, double submits, etc etc etc etc

I always wish I could ship something like that, and it does sometimes start out that way. But it never lasts, not anywhere that cares more about UX than they care about HTML purism.