Answer the question
In order to leave comments, you need to log in
Creating forms by the user?
It is necessary to make the possibility of creating forms in the admin panel. so that the admin can save the form with simple fields (checkbox text and select) and give a name to each field
can there be a ready-made bundle for this? I couldn’t find it, apparently not correctly, I’m looking
in my head to make 3 tables
form
- id
- name
- url
form_field
- form_id
- name
- type (textbox, checkbox, select)
form_value
- useremail
- username
- field_id
- value
it will not be difficult to display this matter,
but here's how to handle the submit? you need to make some Form & Entity classes so that you can process the submission of such a form with a dynamic set of fields
Answer the question
In order to leave comments, you need to log in
Of the often required password (password_again), multi-checkbox, radio and date are missing.
And what's the problem with processing the submit if the first hidden field in the form is its identifier?
1. You need to create a model, in the constructor of which all data must be passed, on the basis of which you can build a form
1.1
Make magic methods for the model, through which it will be possible to process a custom number of fields
models generate form:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$addFields = function (FormInterface $form, FormModel $model){
foreach ($model->getFields() as $field) {
$form->add($field->getName(), $field->getType(), $field->getOptions());
}
};
$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($addFields) {
$data = $event->getData();
$form = $event->getForm();
$addFields($form, $data);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question