0

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.

Karthik N
  • 921
  • 8
  • 16
Raphael Schubert
  • 359
  • 2
  • 21
  • Use foreach($this->input->post() as $key=>$value) { echo $value } access like this – msvairam Feb 23 '16 at 04:54
  • Hello @msvairam tanks for answer... i think, i do not get clearly... how can i manage in database... to got reports, and others things... manage in PHP i know how to... i think i need to explain more in question... thanks... – Raphael Schubert Feb 23 '16 at 04:57
  • I didnt answer your question. Just edited it – CuriousBeing Feb 23 '16 at 04:58
  • Are you need also table structure for this data ? – msvairam Feb 23 '16 at 04:59
  • Sorry @MaxPD... aready changed comment... thanks – Raphael Schubert Feb 23 '16 at 04:59
  • This is not just about managing the data. You need the manage the fields too. Start with designing your tables. Consider Field type(Text, TextArea, Drop Down, Checkbox, Radio), Options(field_type_id, field_option), value(field_option_id, value) This is just to give you an idea that this is a little complex that only handling the data. Production design will differ. – vaibhavmande Feb 23 '16 at 05:00
  • @msvairam Yep... i don't know what logic use to create the database for this specific case... – Raphael Schubert Feb 23 '16 at 05:00
  • @vbrmnd thanks for the answer... yes this i know.. how to create the forms, to me, for now, was easy... i have the logic in mind... but the problem, is how to store the data in a way i can later get reports, and other things from it... like a custom search or filters... – Raphael Schubert Feb 23 '16 at 05:02
  • are you have same field type or different ? – msvairam Feb 23 '16 at 05:07
  • @msvairam will be different type fields... it will can be string, float, boolean – Raphael Schubert Feb 23 '16 at 05:09

3 Answers3

1

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)
msvairam
  • 862
  • 5
  • 12
0

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.

Karthik N
  • 921
  • 8
  • 16
0

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

Community
  • 1
  • 1
Kelvin
  • 690
  • 3
  • 11