I’ve created a widget and I need to allow the user to select from a series of options. The options are books coming from another table in the database.
I’m trying to use code like this:
<input type="text" name="<?PHP $this->get_field_name("books[]"); ?>">
However this fails when trying to save. Is it even possible to pass an array of options like this and save them? If not, what would be an alternative solution. I could pass values like this:
book1
book2
book3
If I do this I would have to have a loop in the update method go through all the books in the database to determine what is checked and what isn’t? I’m open to suggestions.
I’d do something like this:
First, store the options and pick them as an array:
Use this as the field in your form:
or to do it as a checkbox:
Just had the same issue. I solved it by attaching the array part of my name tag outside of my get_field_name call: