mleontenko
5 months ago
160
0
Laravel

Checkboxes from XML template

Posted 5 months ago by mleontenko

I have the following XML template (I plan to keep it as a separate xml file):

<doc>
	<version>1.0</version>
	<option>
		<id>1</id>
		<name>Option 1</name>
	</option>
	<option>
		<id>2</id>
		<name>Option 2</name>
	</option>
	<option>
		<id>3</id>
		<name>Option 3</name>
	</option>
	<option>
		<id>4</id>
		<name>Option 4</name>
	</option>
	<option>
		<id>5</id>
		<name>Option 5</name>
	</option>
</doc>

XML template is not mandatory, another format like JSON can be used. I just need to keep my options structured somewhere. Feel free to suggest something else.

I want to generate form with checkboxes for each of these options like this:

The checkboxes would store selections to array options[]

After submitting the form, I want to store this array into a field named "options", table named "record"

Example:

record:
	id: 1
	version: "1.0"
	options: [1, 2, 3]

I have a few questions regarding this:

  1. What data type should field "options" be?
  2. Will I be able to query this table for options and how? E. g. I want all records containing option 1
  3. What is the simplest way to generate form with checkboxes from template? Also consider that I want to repopulate selections with values from array in case of editing.

Please sign in or create an account to participate in this conversation.