Hi, I’ve been working on my first db-driven website after working my way through the book “Build Your Own DB Driven Website, 4th Ed.” by Kevin Yank.
In the website, I’m trying to set up a form that allows a user to input a new book, and associate a variable number keywords with this book (the user gets to choose how many).
This is very similar to what he does in the book, where a user inputting a new joke can associate it with a variable number of joke categories. The difference is that there are 85 keywords to choose from, so it’s not really realistic to use checkboxes or a drop-down menu. The user has to input these as text into the form.
In addition, I want to use the same functionality to have users enter individual chapter names for each book, so there’s no way to have checkboxes or drop-down menus for that.
I’ve seen this feature on websites before, but I’ve hit a wall when it comes to trying to figure out how to create a form that allows for a variable amount of text data rows to be entered into an array.
If anybody has any suggestions, I’ll be super grateful!
Ask the user to enter the keywords separated by commas in a text box, then:
//Turn the string into an array by splitting on the commas
$keywords = explode(',', $_POST['keywords']);
//Trim any whitespace at the beginning or end of each keyword
$keywords = array_map("trim", $keywords);