How to manage arrays of values
(Select multiple and checkboxes values)

PHPCG is designed to easily manage multiple values stored in a single MySQL field.
The array values are stored in your database in standard format (MySQL SET and ENUM fields) or JSON format (text fields).

The multiple values can be filtered in the READ list, and modified with either select multiple fields or checkboxes.


Types of fields to be used to manage array values

PHPCG accepts both native multiple values fields like SET and ENUM and Text fields using multiple values recorded in JSON.

  • MySQL SET and ENUM fields

    If you use this type of fields, the CRUD Generator:

    • will automatically detect the accepted values.
    • will pre-fill the possible values of the select or checkbox fields.
    • will automatically display the values in the lists views properly, separated by commas.

    The possible values are necessarily predefined by the configuration of MySQL fields from your database.

  • Text fields

    All types of text fields (varchar, text, ...) can accept multiple values.
    The values will be saved in JSON format in the database. They can then be converted into tables and used as values for multiple select fields or checkboxes.

    The accepted values must be defined from the CRUD Generator (see next section).

Defining field values in JSON format (array values)

The array values can:
- either be defined manually one by one (custom values)
- or come from a field in your database (values from the database)


First, open the generator, select your table and validate.

  1. The READ list tab

    • Select the Build READ list tab and scroll down to your field.
    • In the Type dropdown list, select Array (checkbox or select multiple)

      checkbox or select multiple
      checkbox or select multiple
    • Configure the other fields then validate to create the list.
  2. The CREATE / UPDATE forms tab

    • Select the Build Create / Update Forms tab and scroll down to your field.
    • In the Field dropdown list, select Checkbox or Select, then click the Add / Edit values button

      checkbox or select multiple - add / edit values
      checkbox or select multiple - add / edit values
    • custom values

      Simply add / edit the values

      checkbox or select multiple - add / edit custom values
      checkbox or select multiple - add / edit custom values
    • values from the database

      checkbox or select multiple - choose the values from your database
      checkbox or select multiple - choose the values from your database
    • Configure the other fields then validate to create the forms.

Prerequisites

To generate your admin panel with PHPCG you must beforehand:

PHP CRUD tutorial main page