Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

threelyons's avatar

What is the best way to handle dynamic forms?

I am in the process of building a new tool in my application (Laravel 10) that will allow my users to create contact/lead forms within the UI (Filament v3). When I started I thought it would be really simple, but I feel its getting more complicated and wonder if I am overcomplicating things.

The forms can be created as multi-step forms so the DB table looks a bit like below. So the Form is the parent of FormStep and is the parent of FormField. All of this is managed with a Livewire component and Blade file.

Firstly, I wonder if there is a better way to manage that structure. But more importantly, what is the best way to handle the responses? Originally I tried to save the parent Form info into a FormEntry model, with all the responses from the fields added into a JSON column of the FormEntry. But then I started to wonder what could be a better method to handle responses. Should I create a HasMany on the FormEntry and create a new model for FormEntryField ?

Any help/advice would be greatly appreciated. Many thanks in advance.

forms
- id
- name
- type

form_steps
- id
- form_id
- name
- sort_order

form_fields
- id
- form_step_id
- name
- type
- validation
- sort_order
0 likes
5 replies
vincent15000's avatar

I think that storing the responses in a JSON column is not the best way.

I suggest you to create a responses table and store the responses in this table with a foreign key to the question.

You just have to think about how to store the different kinds of responses : true/false, number, text, checkboxes, radios, ...

threelyons's avatar

@vincent15000 hi there, and many thanks for your response. Yes, I was always going to have a responses table. It would be FormEntry possibly that could be named better FormResponse. But, the main question is how to store the responses for each form field. As the forms are dynamic, we never know what fields are in each form, nor do we know how many fields are in each form. Hence why I originally thought about storing the response values in the FormResponse table as JSON. The main fields in the FormResponse would be the ID of the form so we know which form was submitted, along with other important info regarding the form and who submitted it, and where it was submitted from. But overall, the form fields themselves I need to be able to easily consume that data and display it in the UI for the user who created the form. I am gravitating towards having two tables for responses. One for the main form data, then have a FormResponseFields table where the FormResponse has a HasMany relationship with the FormResponseFields... Something like that. What do you think?

1 like
threelyons's avatar

@vincent15000 That is amazing. I didn't think about surveys, but it is the perfect comparison to what I am trying to achieve. The article looks perfect, thank you so much for sharing.

1 like

Please or to participate in this conversation.