jeudi 4 juin 2020

Reading hardcoded values from HTML to process backend results

I have a question about general practices of reading the values from an HTML template to be used to pull data from a backend.

I have an HTML select that is used to filter items in a list from a DB. The top option of the select is a placeholder that has a value of 'Select category'. This is just to signify to the user what the filter does. Having this option selected should not affect the filter value at all though.

E.g.

<select name="filters" id="filters">
    <option>Select Color</option>
    <option>Blue</option>
    <option>Red</option>

Then - in my backend code I'd do something like

let color = $("#filters").val();

//My question is on if this is kosher practice
if (color === 'Select Color') {
    color = null;
}

//getItemsByColor(color)

Just wanna know people's $0.02 on strictly checking values from a template like that. 1 caveat I can think of is if that if the template value changes, so does the code. Are there security flaws with this, etc.. Thanks!

Aucun commentaire:

Enregistrer un commentaire