0
votes

Is there a way to create a dynamic form using Laravel and MySQL? I am trying to build a form, adding to it different fields and input types such as:

  1. text box, text area
  2. radio buttons
  3. checkboxes
  4. file upload

and so on. I am thinking of something similar to gravity forms. The user would customize the form by stating which fields are mandatory, optional or not available.

What I have reach so far is creating the fields normally in the database, have another table responsible for their status as mandatory, optional or off and then displaying them accordingly.

This works normally without any issue. However I am trying to make it more dynamic by defining some sort of generic way to create future forms without the need to create a field for each in the database. Bear in mind that the fields now are just text box.

Would MySQL help doing such forms or would I need to use something like MongoDB?

1
The database engine makes no difference. The only difference is how you'd structure the data within whatever engine you choose. - Atli
@Atli Any ideas how can I structure the data? - omarsafwany

1 Answers

0
votes

The very nature of MySQL is static: you store stuff, persistently ;-)

If I get this right you want users to create a form, using a form that can have any amount of inputs and types, and then store it for later use.

My advice: use VueJS for the dynamic form - it's perfect for something like this! Then, when the user has created the form, either save the full HTML as an escaped blob/text in a single column or use a custom JS object that saves all the chosen options. Something like this:

{
    field1: {
        type: text,
        placeholder: name,
        value: '',
    },
    field2: {
        type: textarea,
        placeholder: 'address',
        style: 'width: 50%'
    }
}

etc.

That way it's easy to retrieve and use (a la Gravity Forms) + with a bit of work you can even have it load again into your custom VueJS form wizard so that the user can edit it later.