A
A
Andrey Markov2017-10-20 01:31:40
Yii
Andrey Markov, 2017-10-20 01:31:40

How to organize validation and saving of dynamic forms in YII?

Good afternoon, I ran into a problem with saving and valuing dynamic fields.
Let's say for example there is a main table in the database, it has some parameters.
Client
- Full name -
Phone
- Address
- Age
- Gender
with a choice of several services)
This is very well implemented in joomla 3 when you can create separate fields of a certain type with a certain set of data for materials and they will be applied to all materials. I roughly outlined the structure of the entity
database
-id
-somefield1
-somefield2
-somefield2
...
attribute
- id
- name // field name
- type // field type
- default // default value
- required // required
- params // here we store all our parameters depending on field type, let's say if we need a drop-down list, then we store something like options => [ option1 => [ name => parameter 1, value => 1], option1 => [ name => parameter 2, value => 2]
attribute_value
- attribute_id // field ID
- entity_id // Model
- value // value
Now closer, to the point, I can't figure out how to write validation and saving entity and additional parameters in activeform.
That is, in the form to display all the fields of the entity model and in the same place to display all the additional fields created by the dynamic. And when saving, all this miracle is validated.
Thanks in advance for your suggestions and ideas.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-10-20
@qonand

1. Read from the database and form an array of parameters from them that you need to fill in
2. Based on this array, form a dynamic model
3. Feed the dynamic model to ActiveForm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question