2

I'm creating a form where a user can add named people with a Name, Address, Phone and Email. There's also a javascript in place that allows a user to add another row/person. When they click this, it reveals another set of fields for Name, Address, Phone and Email for the second person and so on.

My question is how would I then get this submitted into the form in the Control Panel?

I was wondering if anyone has built anything like this before?

Thanks.

5
  • Do you place a limit on the number of such rows the user may add? Commented Aug 21, 2013 at 13:46
  • No, in theory they can add as many as they like. But in reality people will only ever add 2 or 3. Commented Aug 21, 2013 at 14:04
  • 2
    Sounds like you really want a matrix-like fieldtype within your form, which I don't think Freeform would be able to do. Maybe they'll chime in with another solution, but all i can think of is your having to create a set of fields for each possible address the user may add, postfixed with a number (postfixing the fields on the front end of your form when a new row is added). So address_1, city_1, address_2, city_2, etc. and create as many of those sets as you might envision a user adding. Certainly not ideal, but out of the box, certainly possible. Commented Aug 21, 2013 at 15:52
  • Thanks Jean. This was my thought also. A tedious approach but it would work. Commented Aug 21, 2013 at 16:24
  • It's certainly not ideal, but it may be the most straight forward approach. Commented Aug 21, 2013 at 17:11

1 Answer 1

2

Two possible strategies come to mind for this:

  • As another user suggested, create as many Name, Address, Phone and Email fields as you need or think will need, and add a suffix for each field name (eg. name_1, name_2, etc)

  • If you're manually creating your fields in the template using {exp:freeform:form}, add brackets [] to your field names so that you save the data as an array of data. Eg.

    Name: <input type="text" name="name[]" /> Name: <input type="text" name="name[]" /> // etc...

For #2, this will however store all data in a single custom field, separated by a linebreak (not <br />, by the way). For example, in the "name" field in the CP you would have the following stored for three names entered:

Curly
Larry
Moe

You'll need PHP to break those apart if you need them later (using PHP's explode() function or a third-party plugin that does something similar).

1
  • Thank you. We're using regular text form fields and storing them in hidden values right through to the final submit page. At that point i'm using the freeform:form to pass all the hidden values into the the CP. It wouldn't actually be too much of an issue if the name and address data was passed to a single textarea field in the CP. Commented Aug 23, 2013 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.