Shpigford
Shpigford

Reputation: 25338

Where to cleanup user-submitted data?

Users can submit color palettes and I'd like to standardize the format of the hex codes submitted.

Is there a typical way to clean up/standardize this sort of user-submitted data?

In my case, there are four fields where users can enter a hex code. I ultimately want to store it without the pound sign. (So #000000 to 000000).

It's obviously easy to remove the pound sign, but where in the process it should be is what I'm not sure of.

Needs to be server-side as this data can be submitted via other methods than the browser (i.e. API).

Upvotes: 1

Views: 97

Answers (2)

justinbach
justinbach

Reputation: 1955

Everywhere!

You'll definitely want to clean it up server-side, as that's (presumably) where any sort of processing that expects consistently-formatted data to appear, and that's also where you'll be sanitizing user input (which you're doing, of course, right?). Don't trust anything from a remote source on a server!

A bit of client-side auto-formatting wouldn't hurt, though; use javascript to automatically format things and impress your users while doing it!

Upvotes: 1

Nic
Nic

Reputation: 13733

Why not use Javascript to sanitize the data before passing it through to anything? You should be able to easily evaluate the string and make adjustments there before submitting it to your controller/action.

Upvotes: 0

Related Questions