Good day,
I can not figure out how to properly handle a POST request with multiple tags.
There is a POST request from the browser to add a book, the array looks like this:
id:1 header: Kolobok ...:...//ΠΈ Ρ.Π΄. genre1: Π΄ΡΠ°ΠΌΠΌΠ° genre2: ΠΏΡΠΈΠΊΠ»ΡΡΠ΅Π½ΠΈΡ etc. unknown number of genres (how many the user will choose).
So, this array comes to the server (node.js) and to send to the database a request for adding the form: INSERT INTO genre ( genre_id ), ( genre_id ), ( genre_id ) // etc, depending on the number of genres
It is necessary to pull out the records starting with the genre from POST and count their number.
Object.getOwnPropertyNames(req.body).forEach(function(val, idx, array) { if (val == true) {console.log(val + ' -> ' + req.body[val]);} }); Actually the question is how to compare val (this will be the key) with the string genre (1-20)?
And in general, can there be a simpler way?