I
I
inververs2015-04-17 11:38:08
Yii
inververs, 2015-04-17 11:38:08

How is dynamic field validation done?

I don't understand how to validate unknown data. A simple example. Suppose that in the admin panel I can create a form that users must fill out, I call the first field Surname, check the box that it is required, specify the minimum length of 2; maximum 40.
I add the second field - let's say Color, I also define the rules. I have absolutely any fields, what I enter should be displayed to the client.
How best to store it, how best to generate the form, and the question itself is how to do the validation correctly? I understand yii2 and I want to do it right.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
NETChaser, 2015-04-17
@NETChaser

Validation must be done using regular expressions, of course, on the client ... and after POST, also on the server, or only on the server.

I
Ivan, 2015-04-17
@IvanCher

Let the name attribute of the field be some kind of identifier by which it will be possible to find out all its restrictions. In the controller, you submit data for validation of the field model, the model receives rules (restrictions) by identifier, validates, answers the controller, the controller generates a response to the client.

C
Centrino, 2015-04-17
@Centrino

You can create form templates with field descriptions and regular expressions for both back and front, for example in Mongo.

A
Anton, 2015-04-22
@karminski

In my opinion, it is better to define attributes for dynamic fields:
* type (string, int, datetime),
* required (is the field required),
* multiple/single (is it possible to enter multiple values)
* etc. depending on tasks
Well and then to write validators depending on type/required/multiple. Dynamic fields and their attributes are stored in the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question