0

So I have a Post model which has the following fields

title: String,
image: String,
description: String,
tags: [
    { type: String }
],

For creating a post, I made a form that takes inputs for the above fields. For the first three inputs, I just gave <input type="text">. But I am not sure how I can get the input for tags which is an array of strings. I am expecting something like tags = ["html","css","js"] etc. What would be a good way to input these in a HTML form ?

Dev5
  • 449
  • 3
  • 15
  • 2
    If you know what all the strings could be, you can use a ` – Rob Bailey Jan 29 '21 at 15:11
  • if you adjust the input name to be an array (``) and have multiple of these on the page, then `$_POST['tags']` should be an array. Depending on the _type_ of input you want, a multi-select as mentioned above might be best instead of this route. https://stackoverflow.com/questions/4688880/html-element-array-name-something-or-name-something and https://mattstauffer.com/blog/a-little-trick-for-grouping-fields-in-an-html-form/ for more info. – WOUNDEDStevenJones Jan 29 '21 at 15:14
  • 1
    @WOUNDEDStevenJones this works only if the OP is using PHP – TheEagle Jan 29 '21 at 15:18
  • @RobBailey Thanks for that idea, does the `select` input type make each selected inputs into an array by itself? Or do I need to add anything? – Dev5 Jan 29 '21 at 15:24

0 Answers0