Add text fields dynamically on a form.

By: Jo Bo | Asked: 06/30/2024
ForumsCategory: Code HelpAdd text fields dynamically on a form.
Jo Bo asked 2 months ago
Hello, For the past two days I've been desperately looking for a solution to add text fields to a form based on a parameter received by the POST method. In other words, the page on which the form is installed receives a number via the POST method $nbVilles=10; I'd like this to be able to add 10 text fields to receive these city names. I've managed to inject these fields into the form using Javascript, but their responses (values) are not processed and sent by e-mail. I think this is because the identifiers for these fields don't exist in Formidable Forms. Any help I could get would be greatly appreciated, even if it's only a link to a documentation enabling this, which I haven't found despite hours of research on the subject. Best regards. JoBoEVD Translated with DeepL.com (free version)
2 Answers
Rob LeVineRob LeVine answered 2 months ago
You are correct that those fields won't get saved because they're not Formidable fields. At some point, you're going to need to create Formidable fields and the question is whether to do it when the form is created or when the entry is saved. I can't think of a great way to do it after the entry is saved so here's my idea how to create a field beforehand and fill it when the form is saved. Create a repeater field (section) and hide it. When you save the entry, you can create rows in the repeater, one for each city. Use frm_after_create_entry and access $_POST for your data. To create the entries, look at this example however, it is different because repeaters are actually embedded forms, so you have to create the entry in the child form and link it back to the parent (and the parent has to be linked to the child).
Jo Bo answered 2 months ago
Hello Rob, Many thanks for your reply. That's what I thought. I can't really opt for your solution, as there can be up to 50 cities. What's more, in the same form, I have to create 3 other fields in the same way, one of which can be up to 100 dynamic text fields. So I'm going to create them with Javascript and make a PHP code to retrieve and process the answers. It'll be simpler, I think. Thanks again for your reply.   Best regards   JoBoEVD

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right