Jump to content

Storing values in a form that allows a field to be generated multiple times.


Apophenia Overload

Recommended Posts

Say I have a form like this (stored on the Main table):

 

Name ___

Address ___

Phone # ____ +

 

If I click on +, another field pops up

 

Name ___

Address ___

Phone # ____

Phone # ____ +

 

If you click on +, another field is generated, and so on.  I think I have a good idea how to get this to display on the frontend (I'm using CodeIgniter, any tips on that would be appreciated as well).  However, I'm not too clear as to how to store this- how would I store Phone# if there are multiple instances of it?  It is a list, after all.  Would I have to create a table just for Phone #?  And if so, how should I join it with the Main table?

Link to comment
Share on other sites

You could perhaps store the phone numbers as a comma-separated string, like on the phone column if someone had input two phone numbers, you might see

111-222-3333,111-333-444

and use whatever language you choose to split by the comma.

 

otherwise, a table for telephone numbers would work. you could make a table and link them via account names/id numbers/whatever. simple joining syntax might be

select * from `users`, `telephone_numbers` where `user_id` =  `telephone_user_id`

?

Link to comment
Share on other sites

To be honest, it's a bit more complex than numbers.  My table actually has a secondary field associated with Phone #.  So it'd be like this:

 

Phone # _______  (+)

      Ext. _______

 

Upon clicking (+),

 

Phone # _______

      Ext. _______

Phone # _______  (+)

      Ext. _______

 

I'm trying to avoid doing anything fancy to make each Phone # to be paired with the Ext., but I'm not sure if it's possible.  For now, I'm not going to combine each pair into a singleton.

 

edit: Hmm, I suppose I could have a three-table approach.  One Main table, one table for Phone #, and one for Extensions.  The phone # and ext. would be easy enough to match- if there was a number without an ext., I'd just force the frontend to send some sort of symbol so it wouldn't ever be blank.  However, having 3 tables seems a bit clunky...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.