News for hackers. Stuff that matters.
Re:Just Use HTML by niux on Tuesday September 16, 2025 @09:19AM (#45261868)
This article is an oversimplification describing basic forms, but as soon as you try to implement any sort of advanced validation using just HTML, the whole paradigm falls apart. Browsers support JavaScript for a reason.
Re:Just Use HTML by dreadnip on Tuesday September 16, 2025 @09:33AM (#45262045)
How can you ever trust validation on the client side though? The user can just mess with it and submit anything they want anyway.

Why not validate on the server and return a response or error as HTML?

I’m not trying to argue in bad faith here. I know client side validation is necessary in some cases, but IMO it’s only an augmentation for UX purposes on top of server side validation.

Re:Just Use HTML by Tade0 on Tuesday September 16, 2025 @09:39AM (#45262119)
> Why not validate on the server and return a response or error as HTML?

If your form has files you'd want to at least check it before sending data unnecessarily to the server.

Also it's always better to have a tighter feedback loop. That is really the main reason why there's validation on the frontend and backend, not just the latter.

Re:Just Use HTML by prokopton on Tuesday September 16, 2025 @11:20AM (#45263503)
Client-side validation is a progressive enhancement. You always have server-side validation. The validation in the browser exists to provide additional feedback that lets users have realtime feedback about their input.
Re:Just Use HTML by palmfacehn on Tuesday September 16, 2025 @10:13AM (#45262514)
Typically for fetch() I return the error as "text/plain" with the appropriate status code. It is still necessary to give a preflight validation in Vanilla JS, apply an error style and helpful feedback.

HTML has come a long way since the bad old days. General constraints can be applied directly to the input element. It still makes sense add additional explanations for the invalid input with JS though.

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...

Re:Just Use HTML by jonkoops on Tuesday September 16, 2025 @10:33AM (#45262796)
Just use a generic data structure for your validation rules that you can apply on the front-end, and validate on the back-end. Using JavaScript and doing validation on a server are not mutually exclusive.
Re:Just Use HTML by e12e on Tuesday September 16, 2025 @10:23AM (#45262649)
You're answering yourself here: client side feedback/validation is essential ux for any complex form. Even for simple signup forms with a few required fields.
Re:Just Use HTML by carlosjobim on Tuesday September 16, 2025 @11:14AM (#45263447)
You have a human in the loop somewhere. This is how we do to not lose clients who accidentally typed @gmail.co

It's also essential in order to not make forms to difficult to fill in, because that means you lose customers and a lot of money.

Re:Just Use HTML by graemep on Tuesday September 16, 2025 @09:40AM (#45262128)
You can use JS to provide validation and still submit the form from HTML.
Re:Just Use HTML by skydhash on Tuesday September 16, 2025 @10:17AM (#45262573)
That’s not validation. It’s more like helpful hints.
Re:Just Use HTML by fkyoureadthedoc on Tuesday September 16, 2025 @10:20AM (#45262605)
A pointless distinction when we all know what we're talking about.
Re:Just Use HTML by skydhash on Tuesday September 16, 2025 @10:23AM (#45262648)
Is it? I’ve seen devs bring complicated code to the frontend when a required attribute on the tag would have done the job just as well. Preventing user mistakes is not the same as ensuring correct input.
Re:Just Use HTML by fkyoureadthedoc on Tuesday September 16, 2025 @10:30AM (#45262760)
We've all seen bad implementations of any given thing I'd imagine. Ever submit a form that triggers a full page refresh after about 8 seconds of hanging, only to lose half the data and reveal some arcane requirement to you that wasn't stated up front? Of course this isn't the proper way to do it, but it happens.
Re:Just Use HTML by graemep on Tuesday September 16, 2025 @10:39AM (#45262899)
What is the difference?

The same is true for any JS "validation" and I was using common terminology.

From a user point of view as long as you keep the feedback loop short what difference can they see?

Re:Just Use HTML by cenamus on Tuesday September 16, 2025 @10:24AM (#45262662)
Neither is it validation when you use JS if the server doesn't check it. You can always send requests with postman, curl or your tool of choice.
Re:Just Use HTML by naasking on Tuesday September 16, 2025 @10:26AM (#45262692)
Helpful hints are all you can rely on from client-side. Client-side validation doesn't really exist, true validation only happens server-side.
Re:Just Use HTML by norman784 on Tuesday September 16, 2025 @09:45AM (#45262209)
You can have a minimal library like HTMX or if you have access to a solution Phoenix LiveView, you need minimal JS to have an interactive page, the only downside is that you could introduce some latency because of the network trip.
Re:Just Use HTML by leftyspook on Tuesday September 16, 2025 @09:33AM (#45262050)
I think a part of the point is to question the need for things like that. Do your users actually need all of these bells and whistles?
Re:Just Use HTML by port11 on Tuesday September 16, 2025 @03:48PM (#45267060)
There's a lot of validation that can be done with HTML; I'd even say most client-side validation can be handled by HTML/the browser. You can specify input types, do RegExp matching, etc. There's a lot in the spec.

You'll need server-side validation anyway…