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

mehany's avatar
Level 13

Clever way to build dynamic forms

Context: In a system that involves serving dynamic forms.

Challenge: There are few ways to build a dynamic form that is based on the user selection of a given option. Making the right decision to whether I should depend on Java Script Interaction entirely (Angular - react - or jQuery with a nice MVC structure ) or Should I go with a simple back-end structure that makes use of the Service Container with some other design patterns that will depend on a simple front-end "On Change" JS event followed by an Ajax call.

Complexity: Different business departments, each may have an endless amount of forms and of course down the road, in like 2, 3 years, there will be changes.

Example: Facebook business forms are fairly complex.

Package to use: https://github.com/kristijanhusak/laravel-form-builder

[ Edited ] Added complexity

0 likes
7 replies
mehany's avatar
Level 13

I hear a whisper -> use Angular for front-end and the above package to generate forms !

mirago's avatar

I've been using this package for a couple of months now. The best form generator I've ever used with laravel.

pmall's avatar

It really depends the level of dynamism and the different options available to create the form. But the form builder above seems a pretty good solution to create dynamic dynamic form based on user options.

But i cant figure out why you mention on change event and ajax call in this case, if you output the html.

mehany's avatar
Level 13

Just trying to think a loud what I am going to do in the front-end if the main type of the form has changed

 ObjActionFormOne
      --options
 ObjActionFormTwo
      --options

...ecc
mehany's avatar
Level 13

@pmall I added complexity above. What you think is the way to go about building such a functionality within an existing application?

vrtrainer's avatar

I'm building something like this at the moment and I'm going for the JS approach with "On change" events, when/if users are choosing another form template.

My backend is serving a JSON object for the frontend (template id, input type, name and so forth) to build out the form. If the user changes the template, I make an AJAX call to the backend, which serves a new JSON object for that new form. I chose this approach since it seemed more dynamic and also the JSON approach made it possible to switch the frontend implementation pretty easily.

Please or to participate in this conversation.