Reputation: 359
The problem:
Create custom forms, and fields. Manage the Data;
I`m creating an CMS with PHP and Codeigniter. My client will need manage the form fields by itself. Because they can change... today will be around 20 fields. But next month will be 23.
I know how to make a logic to create the forms. But how can i manage the data?
Serialize the data and save in one field on table, will not be helpfull i think, because, how can i do a quick search/filter in table in serialized data?
Someone already got this problem? Maybe can help me build a small logic here to get a way to work.
Just in case someone asks, with Codeigniter, I`m able to do something like this:
$formData = $this->input->post();
and get something like this:
$formData = array(
[fieldName] = 'Value',
[fieldName2] = 'Value 2'
[fieldName3] = 'Value 3'
);
So get the data, was easy.
Upvotes: 0
Views: 678
Reputation: 690
I think your problem is in database struct :
How can manager table with dynamic columns.
Maybe you can find answer at link: MySQL pivot table query with dynamic columns
Upvotes: 0
Reputation: 951
To manage the dynamic php form, You can add a new table for managing the form fields. The table will contain the information about the fields in the form. Since you said it can be changed by the user then the input fields can also be updated for. Eg: Form table: form_id, field_id, input type, validation, mandatory field
Then based on the form table values you can manage form submission in php. i.e based on your requirement normalize the table structure. In php your for loop for iterating each inputs. Use the input field id as a name in form.
Upvotes: 0
Reputation: 872
This table structure for dynamically created form
frm_fields table
field_id
field_title (the title that appears beside the field on the form)
field_level (defines the level of the organisation at which the field is represented e.g. global or office level)
field_view (defines which view the field relates to in the erp system used by the business)
field_block (defines the block of fields it will appear in on the form)
field_technicalName
field_side (value is either 1 or 2 which defines whether it appears on the left or right of the 2 column block)
field_type (defines whether it is a text, select, checkbox field etc.)
field_length (defines the max character length of the field)
field_width (defines the size of the field as it appears on the form)
frm_active table
form_id (each form request will of course have a unique id)
field_id (foreign/primary key of the field from the table above)
field_value (the value they have entered for this field)
Upvotes: 1