This section covers the information regarding the form submission via ajax with usage of the internal logic. This particular example covers the form for a module(system wide logic for forms is pretty much the same)
Define a new form in the:
/src/Form//Modules/<moduleName> the same way that other forms are already defined.
There is no particular need to keep the form in given subfolders - it's just all about keeping the code & structure more organized.
Also to keep the code consistent - update the:
It is also possible to create a form by calling symfony command:
The most important thing is just to have a route which will contain the form validation and data insertion logic.
It can be either separated route like
/<moduleName>/create-entry-via-form, or this can be handled the way it's done now:
submitForm method can contain any logic related to extracting/converting data from request, but what really matter is
to have implementation of form submission:
There is no requirement to flush the entire entity, anything could be defined at this step, like for example updating just few entries in DB.
Defining JS data processor
DataProcessor, it's only goal is to read the data from the form, handle user defined
logic in callback and forward the gathered/fetched values to the backend action.
Data processors are defined in:
There are 2 particular files used for handling form submission (and CRUD overall - but about that in the other section):
Both files consist the same type of logic, the sole purpose of this separation is to keep the code organized, since
Entity.ts contain definitions for creating whole
Entities upon submission and
SpecialAction.ts contain logic for
updating for example single cells in DB.
Binding JS logic in template
Take a look on this example:
- The parent element must have :
- data param
data-typeequal to the definition of entity in the Js,
- data param
- The form element must have
data-entityalso equal to the definition of entity in the Js,