A
A
Alexey Sklyarov2020-12-13 09:42:38
Laravel
Alexey Sklyarov, 2020-12-13 09:42:38

How to store information about fields used in forms?

As the project develops, it begins to acquire a different number of forms (authorizations, adding / deleting model material, etc.). Already now I understand that there can be a problem when you need to add a field to a form that is used in several places for example. The idea arose to create, for example, a config file in which to write all the fields for each specific form, for example:

[ type => "text", "name" => 'post_title', "lable" => "Заголовок поста", "required" => true]

But I'm not sure that it is advisable to store such data in the config. How can such data be stored in the application, is it necessary to store it at all, or are there other more correct options (and maybe even examples)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sanes, 2020-12-13
@Sanes

Write a form builder. Types and names of fields store in the corresponding table of a DB.

I
Ilya Chubarov, 2020-12-13
@agoalofalife

The documentation has some solutions to this problem.
You can use components, subview, sections. Accordingly, you can cut your layout as you like and reuse it.
And regarding the dynamic substitution of fields in forms, what profit will you get?
Probably it will be according to DRY, (Don't Repeat Yourself) only there is a downside:
- the form is also validation, you will have to solve this and that somehow
- you will bring your own developments into the project, which will only complicate its support by other people and you .
- Spend extra time on development
Vzvest everything - the best is the enemy of the good.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question