Creating Multiple Contact Records via Form Submissions

This tutorial covers implementation of a registration form that will create two or more Individual contacts, with relationship to a Company contact.

There are three types of Relationship:

  • Individual to Individual - This relationship is between two Individual contacts. It uses prefix of 'I2I_'. For example:
    I2I_Parent
    I2I_Guardian
  • Individual to Company - This relationship is between a Company contact and an Individual contact. It uses prefix 'I2C_' followed by the relationship term. For example:
    I2C_AccountsContact
    I2C_Owner
  • Company to Company - This relationship is between two Company contacts. It uses prefix of 'C2C_'. For example:
    C2C_Supplier

This tutorial will focus on Individual to Company relationship. To learn more about Companies and Relationship, read this article.

Company with Individual Contact

The form below will create two types of contact and create an "Owner" relationship between the Company Information and Primary Contact.

Company Contact

  • Company Name
  • Phone Number
  • Email Address
  • Relationship [hidden]

Individual Contact

  • First Name
  • Last Name
  • Phone Number
  • Email Address

The Form

To get started, add the following form code to a page:

<forms:form id="membership_i2c" contactmode="register" onsubmitredirect="/community/register/success/"> <forms:hidden id="contact_company_relationship_id" value="I2C_Owner" /> <h5>Company Information</h5> <forms:row type="one_column" label="Company Name"> <forms:editbox width="100%" id="contact_company" placeholder="Company / Organisation Name" validations="mandatory" /> </forms:row> <templates:row> <templates:column width="6"> <forms:row type="one_column" label="Company Phone"><forms:editbox id="contact_company_phone" width="100%" /></forms:row> </templates:column> <templates:column width="6"> <forms:row label="Company E-mail" type="one_column"> <forms:editbox id="contact_company_email" validations="mandatory,email" transformations="tolower" /> </forms:row> </templates:column> </templates:row> <h5>Primary Contact</h5> <templates:row> <templates:column width="6"> <forms:row label="First and Last Names" type="one_column"> <forms:editbox id="contact_first_name" validations="mandatory" placeholder="First Name" /> </forms:row> </templates:column> <templates:column width="6"> <forms:row label="&nbsp;" type="one_column"> <forms:editbox id="contact_last_name" validations="mandatory" placeholder="Last Name" /> </forms:row> </templates:column> </templates:row> <templates:row> <templates:column width="6"> <forms:row type="one_column" label="Phone Number"><forms:editbox id="contact_phone" width="100%" /></forms:row> </templates:column> <templates:column width="6"> <forms:row label="E-mail Address" type="one_column"> <forms:editbox id="contact_email" validations="mandatory,email" transformations="tolower" /> </forms:row> </templates:column> </templates:row> <forms:row type="one_column" align="center"><forms:submitbutton>Register</forms:submitbutton></forms:row> </forms:form>

Creating Company Contact

The form field for the Company Information has the same following commonly used attributes:

id="contact_company_[FIELDNAME]"
If your form will create a new contact record in the database, each form field should use ids that match the contact database fields. (eg. use contact_company_phone, contact_company_email, contact_company_phone_work). You can view all contact fields here via the API reference.

id="contact_company_relationship_id" value="I2C_Owner"

Create a hidden field to assign the relationship between two contacts. In this example, the relationship is I2C_Owner. Default: I2C_Employee

Company with Multiple Individual Contacts

You can expand on the above form to allow additional Individual contacts to be associated with a Company. This approach is commonly used to extend Company Information with multiple contact relationship.

In the example code below, the Form will create a Company Contact and three (3) Individual Contact with Owner, Manager, and Employee relationship respectively.

The Form

<forms:form id="membership_company_tree" contactmode="register" onsubmitredirect="/community/register/success/"> <forms:hidden id="contact_company_relationship_id" value="I2C_Owner" /> <ajax:event id="updatecompanyname_ajaxevent" updateregions="updatecompanyname_ajaxregion" /> <forms:row type="one_column" label="Company Name"> <forms:editbox width="100%" id="contact_company" placeholder="Company / Organisation Name" validations="mandatory" onkeyupajax="updatecompanyname_ajaxevent" /> </forms:row> <h5>Owner Information</h5> <templates:row> <templates:column width="6"> <forms:row label="First and Last Names" type="one_column"> <forms:editbox id="contact_first_name" validations="mandatory" placeholder="First Name" /> </forms:row> </templates:column> <templates:column width="6"> <forms:row label="&nbsp;" type="one_column"> <forms:editbox id="contact_last_name" validations="mandatory" placeholder="Last Name" /> </forms:row> </templates:column> </templates:row> <templates:row> <templates:column width="6"> <forms:row type="one_column" label="Phone Number"><forms:editbox id="contact_phone" width="100%" /></forms:row> </templates:column> <templates:column width="6"> <forms:row label="E-mail Address" type="one_column"> <forms:editbox id="contact_email" validations="mandatory,email" transformations="tolower" /> </forms:row> </templates:column> </templates:row> <ajax:region id="updatecompanyname_ajaxregion"> <h5>Company Employees</h5> <forms:form contactmode="store"> <forms:hidden id="registration1_relationship" datacolumn="contact_relationship_id" value="I2C_Manager" /> <forms:hidden id="registration1_company" datacolumn="contact_company" value="[? $contact_company.getValue() ?]" valueignore="ajax" /> <templates:row> <templates:column width="8"> <templates:row> <templates:column width="6"> <forms:row label="First Name" type="one_column"> <forms:editbox id="registration1_first_name" datacolumn="contact_first_name" validations="mandatory" placeholder="First Name" /> </forms:row> </templates:column> <templates:column width="6"> <forms:row label="Last Name" type="one_column"> <forms:editbox id="registration1_last_name" datacolumn="contact_last_name" validations="mandatory" placeholder="Last Name" /> </forms:row> </templates:column> </templates:row> </templates:column> <templates:column width="4"> <forms:row label="E-mail Address" type="one_column"> <forms:editbox id="registration1_email" datacolumn="contact_email" validations="mandatory,email" transformations="tolower" /> </forms:row> </templates:column> </templates:row> </forms:form> <forms:form contactmode="store"> <forms:hidden id="registration2_relationship" datacolumn="contact_relationship_id" value="I2C_Employee" /> <forms:hidden id="registration2_company" datacolumn="contact_company" value="[? $contact_company.getValue() ?]" valueignore="ajax" /> <templates:row> <templates:column width="8"> <templates:row> <templates:column width="6"> <forms:row label="First Name" type="one_column"> <forms:editbox id="registration2_first_name" datacolumn="contact_first_name" validations="mandatory" placeholder="First Name" /> </forms:row> </templates:column> <templates:column width="6"> <forms:row label="Last Name" type="one_column"> <forms:editbox id="registration2_last_name" datacolumn="contact_last_name" validations="mandatory" placeholder="Last Name" /> </forms:row> </templates:column> </templates:row> </templates:column> <templates:column width="4"> <forms:row label="E-mail Address" type="one_column"> <forms:editbox id="registration2_email" datacolumn="contact_email" validations="mandatory,email" transformations="tolower" /> </forms:row> </templates:column> </templates:row> </forms:form> </ajax:region> <forms:row type="one_column" align="center"><forms:submitbutton>Register</forms:submitbutton></forms:row> </forms:form>

To explain:

Inside your form, create additional <forms:form> per contact with contactmode="store":

<forms:form contactmode="store">
    <forms:hidden id="registration1_relationship"
        datacolumn="contact_relationship_id" value="I2C_Manager" /> 
    <forms:hidden id="registration1_company"
        datacolumn="contact_company" value="COMPANY_NAME" />    
    <forms:editbox id="registration1_first_name" datacolumn="contact_first_name" />
    <forms:editbox id="registration1_last_name" datacolumn="contact_last_name" />
    INSERT ADDITIONAL CONTACT FIELDS HERE
</forms:form>


1. Add field for datacolumn="contact_relationship_id" value="I2C_Manager" to assign relationship between Company and Individual contact. In this example, we will assign the contact to Manager relationship. Note: Use a different ID per contact to avoid overriding the contact_relationship per contact.

2. Add field for datacolumn="contact_company" value="COMPANY_NAME". This will define the Company contact associated with the Individual contact. In the example above, it uses ss:ajax:event to populate the company name from the user input above the form.

3. When adding contact fields for the Additional contact, make sure to assign a unique ID per field then use datacolumn="" to link the form item to a Contact Field.

Other Optimisation:

  • Allow Relationship Type to be selected by the user:
<forms:row label="Position"> <forms:combobox id="contact_company_relationship_id" datacolumn="contact_company_relationship_id" datasource="\Components\Customers\Contacts\Relationships\Types::getAllForRelationshipCategory('I2C')" as="relationship_type" datatitle="$relationship_type['relationship_type_title']" datavalue="$relationship_type['relationship_type_id']" /> </forms:row>