[SOLVED] I need a simple but dynamic form

I need a simple but dynamic form. Let me explain by example. Let say an insurance firm needs you to list all the members of your family where each member is defined by 3 fields (Name, Sex, Age). The 3 fields would be oriented horizontally and if you want to add a new member you can press a small + button to add a new set of fields for a new family member or press a - button to subtract a set of fields (member) that you do not want to list.

Is there any way to achieve this?

It is possible, there are a couple of things you need to do to make this work.
The JavaScript for adding and removing the fields and also the form handler needs to be written in PHP to email the form data.
The only method I know of (used in the past), is to store all those dynamic fields into a single array to parse to the form handler.

I’m not going to build it for you, but it heads you in the right direction.

If you need a ‘subtract’ button @PeteSharp has the answer. However, if you need only an ‘add’ button you could do this in Blocs itself as shown here: https://builtwithblocs.com (click on: submit your work). Inspecting the element shows you how to do so.

I’m only on my phone. But I’m assuming that’s using hidden fields??

If so, for client work you wouldn’t them to be receiving emails with a pile of empty fields. Allowing for a family of 5 would be 15 of them.

Correct. :+1:

Well, the question is: “I need a simple but dynamic form”
Your solution would be a much neater approach but it stretches the definition ‘simple’. :grin:

I read that as they have a simple form of a few fields. :wink:

IMO - my approach would be best for a client. Which I am assuming this is for.

2 Likes

Can’t agree more… :innocent:

@PeteSharp and @Jerry - Thank you for your kind input and willingness to help, much appreciated.

As I am not a coder, I think I need to keep this as simple and functional as possible. Maybe the dynamic aspect is not necessary, I’m going to try and build a form that has 15 sets of fields for 15 people. Hence, users would just fill-in the form depending on the number of people in their family. Blanc fields can just remain blank as long as the information in the populated fields are submitted successfully.

Is there a way to do the following:-

  1. In the case where ‘Name’, ‘Sex’ and ‘Age’ is required for each person, is there a way to prompt the completion of the fields per person?. Example: if a name field is populated then the sex and age fields become mandatory to populate.

  2. Is there an easy way to filter out the blanc fields when the ‘Send’ button is hit?

Both those require coding.

Your alternate option is to look into buying a form generating script/service. And embedding the form on your page.

2 Likes

Are there any brics designed for such goals?

No, not yet. But feel free to create one. :grin: There are a few easy-to-implement scripts/service providers discussed in previous topics.

Hi @Samazar , I know a few people who have needed multi step forms for business information they needed to collect, they used Easyforms as this opened the door for more creative forms and true data caputuring.

This might give what you need and it’s pretty cheap too: https://easyforms.dev/

@Mattheus is a big user and knows it well.

1 Like

How does one embed the form? - Is it a matter of copying the code and pasting it in the header or footer of the page. Is it possible to save it as a bric?

Thanks @AdieJAM, actually I’ve just realised that there is no need for a subtract button. I would indicate just one set of fields (Name, Sex, Age) and the user should be able to add additional sets of field if needed - just like in the reference she provided by @Jerry.

Hi Jerry, I think having only an ‘add’ button would be sufficient. Any idea how that was done?

Something like this would be ideal and sufficient:-

Hi @Samazar. It’s just a simple toggle visibility as mentioned earlier.
Kapture 2021-08-27 at 19.34.39

More info and video here: Toggle Visibility – Blocs – User Documents

I hope this helps.

1 Like

Thank you very much indeed @Jerry

@Jerry - How does a form look when it is filled and emailed? - Any way to test it or preview it without hosting it?

Forms only work when hosted.

2 Likes