Iām writing a form builder plugin and to display the collected data of a form I need a dynamic structure. Here is an example to clarify what I mean:
A user creates a form with a first_name and a last_name field with the form builder plugin. Than this form can be used to collect data. The form builder plugin stores this data as entries in a structure field. To display this data in the panel I need to set the fields of the structure. But because the fields are created dynamically by the user I canāt write them in the blueprint directly. Is there a way to generate the fields for the structure dynamically? Something like this (where generateFields could be defined in the page controller):
Dynamically created page from received data with Page::create.
Problem is - that I can not see that page in panel, because it does not have appropriate blueprint.
Two points that I do not understand:
how can I get received data in blueprint plugin (so I could iterate through data and create dynamic page fields).
If amount of page fields varies - does it means that I need to create blueprint for each situation - survey3.yaml survey7.yaml etc
The problem with dynamic blueprints is that ā as I wrote in the recipe and mentioned above ā you donāt have access to the current page object. You can fetch a specific page via the page helper, but that doesnāt really make sense if you have multiple pages created programmatically.
So I have /controllers/upload.php which receives data when frontend sends data to /templates/upload.php which calls Page::create($params).
Got a bit confused - Page::create has props: ātemplateā which actually is name of blueprint, but there is also prop āblueprintā which sets blueprint object? Was trying to define blueprint fields hereā¦ could not manage to work it.
What I want to achieve - in same place where I create page (with received data) would like before or after define and create blueprint for that page (with defined text fields for each received form input).
Normally my blueprint would look like this:
name:
label: Name
type: text
surname:
label: Surname
type: text
question1:
label: Question 1
type: text
question2:
label: Question 2
type: text
... etc
One user will answer on 3 questions, other user will answer on 7 questions. I could hardcode maximum possible question fields in blueprint, but instead want to create that blueprint dynamically in moment when receive data from frontend.
I have blueprint like @arnoson where I can define form fields like structure items and I wanāt define submissions fields for this dynamic form fields. I understand correctly that this is not possible?
But I need reuse blueprint for multiple pages. How can I get actual form fields for submissions fields definition if current page is not accessible? Thanks