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

kramsuiluj's avatar

Creating Forms with Dynamic Input Fields

Currently, I'm in the middle of developing a school project for now it is a simple records management system.

I need some opinions or advice on how to implement this feature, which is kind of a form template, I don't really know what to call it, but it is similar to google forms, where you can create a form by adding input fields.

I don't really know how it works and I haven't started developing it yet, but I've been thinking about it for quite some time. So, my guess is or at least my approach is to store it as a JSON.

So, for example below is a form with an input field for first name:

{
	"firstname": {
		"id": "firstname",
		"type": "text",
		"name": "firstname"
	}
}

I haven't really gotten far with Laravel yet, but I can say that I can make some basic CRUD app without difficulties. I need help to decide if I'm on the right track and also want to learn other approach on this problem. Thanks!

0 likes
4 replies
Ben Taylor's avatar

My advice to you is just go with what you have and build on it. It may not be the best solution, but that doesn't really matter. You will gain a ton of experience thinking it through. This is just a school project after all.

Things you may want to consider allowing for:

  • different kinds of form controls (selects, textarea, checkbox, etc)
  • labels
  • Attributes (e.g. disabled, step, required etc)
  • Front end validation logic
1 like
kramsuiluj's avatar

@Ben Taylor I was thinking about how I would handle the validation too and there is no way to do the validation on the back end right? unless you know the names of the input fields, which in this case you don't because its dynamic, meaning it can be anything.

Tray2's avatar

@kramsuiluj The validation rules is just an array, so it would be possible to fetch those from the database as well.

So when you build the form, you also add the validation rules for each form element.

I would however not store them as json.

I would use a proper database model for it.

I suggest reading this post for more information on how to think about the database.

https://tray2.se/posts/database-design

1 like
kramsuiluj's avatar

@Tray2 Thanks a lot for the info, and I really like the article, I usually like articles like that since it's so easy to understand and packs a lot of information.

1 like

Please or to participate in this conversation.