Skip to main content

Create contact using custom field in civicrm 4.0 (civicrm API)


Create contact using custom field in prifile when event registration.
Create Contacts using API in civicrm 4.0 in drupal 7 on post process.
 If the contact exists then it o/p that contacts id & if not exists then it create new contact & gives the o/p .

function eventType_customPath_civicrm_postProcess( $formName, &$form ){
    if( $formName == 'CRM_Event_Form_Registration_Confirm' ){
        $participantContact = $form->getVar('_params');
        $participantFirstNameId = array( 'custom_11', 'custom_15', 'custom_19' );   /* add custom first name Id */
        $participantLastNameId = array( 'custom_12', 'custom_16', 'custom_20' );    /* add custom last name Id */
        $participantEmailId = array( 'custom_13', 'custom_17', 'custom_21' );       /* add custom email Id */
        $participant = array( );
        for( $count = 0; $count < 3; $count++ ) {
            $participant[ $count ][ 'firstname' ] = $participantContact[ $participantFirstNameId [ $count ] ];
            $participant[$count]['lastname'] = $participantContact [ $participantLastNameId [ $count ] ];
            $participant[$count]['email'] = $participantContact [ $participantEmailId [ $count ] ];
        }
        require_once "api/api.php";
        foreach( $participant as $participantKey => $participantValue ){
            if( !empty( $participantValue['firstname'] ) && !empty( $participantValue['lastname'] ) ) {
                $searchContact = array ( 'first_name' => $participantValue['firstname'] , 'last_name' => $participantValue['lastname'], 'version' =>3 );
                $contact = civicrm_api( 'Contact', 'Get', $searchContact );
                if(isset($contact['value'])){
                    $contactId[]['contact_a'] = $contact['id'];
                }else{
                    $createContact = array ( 'first_name' => $participantValue['firstname'] , 'last_name' => $participantValue['lastname'], 'email' => $participantValue['email'],'contact_type' => 'Individual', 'version' =>3 );
                    $contact = civicrm_api( 'Contact', 'Create', $createContact );
                    $contactId[]['contact_a'] = $contact['id'];
                }
            }
        }
    }
}

Gives the o/p as 
$contact 

[0]=>
          array(
                   [contact_a] => 123
                 )
[1] => array(
                    [contact_a] => 124
                    )

Comments

Popular posts from this blog

Create Hooks in Civicrm in Joomla 1.5

  Create Hooks in Civicrm in Joomla 1.5 Create folder in any directory like /Joomla/media/civicrm_hook . Create file civicrmHooks.php in this directory. Go to Administer CiviCRM > Global Settings > Directories Set the path for custom php here. Use the civicrm hooks with Joomla_civicrm_hookName format. Ex. function Joomla_civicrm_buildForm( ){ // Write your code here. }

Some of the good sentences that one should keep in mind.

Don’t compare yourself with anyone in this world. If you do so, you are insulting yourself.  You are not responsible for what people think about you . But you are responsible for what you give them to think about you. A man is lucky if he is the first love of a woman. A woman is lucky if she is the last love of a man. Write your Sad times in Sand, Write your Good times in Stone. Behind every successful man, there is an untold pain in his heart. Without your involvement you can't succeed. With your involvement you can't fail. Love your job but don't love your Company because you may not know when your company stops loving you. You may get DELAYED to reach your Targets. But every step you take towards your target is EQUAL to Victory. It's better to loose your Ego to the one you Love, than to loose the one you LOVE because of EGO. Don't make promise when you are in JOY . Don't reply when you are SAD. Don't take decisions when you are ANGRY. Think twice, Act w...

New Services to the world

Different government services & Online Services GST Registration Company Registration ITR PAN Card Aadhar Card E-way Bill Registration Food License Accounting Service Website designing Website development Website Hosting Website Domain Website Testing (Manual) Website SCO Optimization Lead Generation Add Creation and many more...