Forums

Parent child relationship on form

samoht 23 Jun, 2010
Hello all,

I am trying to code a form that will store phone and address info for a directory. I want to be able to indicate if the person is a head of the house hold so that all others living in that house would be collected under him/her. This is especially important because the directory will likely have several different houses with the same last name. My final output would look like:

Smith, John & Sally
Jenny & Joe
123 Here Ave
hometown, PA 17782

Smith, Terri & Barbra
Christi
432 There Dr.
hometown, PA 17782

etc.

Currently I have created the form with a radio button for House Head? (yes, no).
But now I need to set it up so that if the answer is NO - they get to select a House Head from a select box. Then I need to save a parent_id for all children.

Any ideas??

thanks,
charles1926 23 Jun, 2010
Why not make the post code and house number the primary field and then you can link the head of house and others to it.
samoht 23 Jun, 2010
yeah that sounds like what I want to do - but how will I set up the form to save the house number as the primary field?
would I use a hidden input that has a condition to check the head0 radio and then add the number for the house based on that?

thanks,
GreyHead 24 Jun, 2010
Hi samoht,

This can get very complex very quickly. You need to give some careful thought to the database design on paper before you go much further and work through some test cases: for instance - what happens if there are two families at the same address?

This is not easy stuff to get right!

You might want to take a look at the database table structure used by CiviCRM (or even use CiviCRM for your application. It is a very nice example of a database structure designed to hold information about people, households, addresses, contact info and more. The Joomla demo is here, and see this page in the docs for an idea of the structure.

Bob
samoht 24 Jun, 2010
Wow! Thanks for that Bob.

I'll take a look at their structure for sure.
For now - I added a field called parent_id in the table. On the form if the user is a 'Head of Household'(hoh) then I use javascript to give parent_id the value of 0. If the user is not hoh then I display a select box of all the hoh in the db (i.e. all contacts with a parent_id = 0 ) Since that select box is pulling from the table the cf_id of the hoh I then just assign their cf_id as the parent_id. This solves some of my problems, but I agree that this can get complex quickly.

Thanks again for the tip -
I'll let you now how it goes.
This topic is locked and no more replies can be posted.