Techniques for maintaining data consistency on the front end

2

Example : In a form, some fields ( input ) are loaded via ajax from a select . The% selected% will be used in the backend to validate those fields.

However, the user can load a certain option, fill in their fields, and intentionally change the value (in the browser) of the selected option tag to another valid value, for example, and forward it to the server.

How to ensure consistency of data coming from an HTML form? Which techniques / methods are essential?

  

I understand that this can be handled with certain conditions in the backend. My search is for which are the best practices. For example, I think that for every option , I should store an identifier token in a option , so I could easily check if the data is referring to the selected option.

    
asked by anonymous 12.08.2015 / 04:59

1 answer

2

The correct form is the one you are already doing, trying to validate directly in the browser and still have another validation on the server before executing the commands sent by the user.

This type of problem is not exclusive to HTML but any application that has a client and a server, where we perform validation on the client to avoid unnecessary connections with the server and still another validation on the server of any data that is sent by the client, there will always be this double validation.

What I did and recommend to avoid code repetition was to put all the validation in the data model that was shared between both, so I could call Person. Validate would return me true or false indicating if it passed, outside that would have also methods to get validated object error lists.

    
12.08.2015 / 10:16