How to organize work and validation as well as CRUD for backend and frontend. Backend and Frontend communicate via AJAX. That is, somewhere the logic is:

FrontendForm (React.js) generates a form with fields that are validated (Required fields, value range, data format) and, if successful, are sent to BackendForm (PHP), which in turn is also validated (Required fields, value range, data format) in case of an error, the response is returned to the FrontendForm with the fields that caused them and the text of the errors. If there are no errors in the form. Then the controller creates a BackendModel that also has its own validation, but already at the level of working with the database (Required fields, data type, uniqueness, connections)

Now we will consider several possible situations that cause some difficulties:

Suppose the registration stage is divided into several steps. And each step is a bundle from the BackEndForm / FrontendForm set for each step. And they are saved in LocalStorage / Session, files are loaded, etc. In the last step, the data is collected in a single form and stored in the database.

Now edits come to the design and the field is transferred from the first step to the second. And it is already necessary to correct the validation and list of fields in two places (FrontendForm and BackendForm).

Suppose a client comes not through a browser but through a mobile application, and there is no longer React, but something else. That is, only the Frontend is changing. Backend works in the same way.

Or let's say the option when the logic changes in the backend, we add one more field to the database, and therefore the fields for validation in BackendModel, BackendForm and FrontendForm.

Who else does, or can there be any standards, technologies and other buns for this?

So that the rules of validation for Frontend, the list of fields, and so on were formed from Backend. There may be some abstract format understandable as Backend and Frontend. Wsdl or something like that.

    1 answer 1

    I remember this solution: On the Backend side, a model is created which contains in itself a description of the data to be obtained (type, length, whether it is necessary to fill out). After that, the model was transferred to FormBuilder, which in turn generates html and JS. When data is received from the front-end, the validator is again submitted to the validator. But this is only a theory. You can implement it or use ready-made solutions.

    - xCrud

    - Simple crud

    If you use some framework, then most likely smart validation on them will be natively implemented well, or at least at the level of extensions there should be options.