You are here

function _civicrm_entity_profile_process_profile_submitted_data in CiviCRM Entity 7.2

Processes the submitted form data via CiviCRM Profile API

Parameters

$profile_id:

$submitted_data:

$contact_id:

Return value

bool|array

2 calls to _civicrm_entity_profile_process_profile_submitted_data()
civicrm_entity_price_set_field_display_form_event_submit in modules/civicrm_entity_price_set_field/includes/civicrm_entity_price_set_field.event_registration.inc
Submit handler for event registration form 'Register' button
_civicrm_entity_price_set_field_process_event_registration in modules/civicrm_entity_price_set_field/includes/civicrm_entity_price_set_field.event_registration.inc
Process event registration (after contacts deduped and reg status checked, successful cc transaction if paid event)

File

modules/civicrm_entity_profile/includes/civicrm_entity_profile.profile.inc, line 135
CiviCRM Entity Profile, Profile Form generation and processing, utility functions

Code

function _civicrm_entity_profile_process_profile_submitted_data($profile_id, $submitted_data, $entity_type = 'contact', $contact_id = 0) {
  try {
    $params = array(
      'sequential' => 1,
      'profile_id' => $profile_id,
    );
    foreach ($submitted_data as $name => $value) {
      if (is_array($value)) {
        $temp_param = array();
        foreach ($value as $v) {
          if (!empty($v)) {
            $temp_param[] = $v;
          }
        }
        if (!empty($temp_param)) {
          $params[$name] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $temp_param);
        }
      }
      else {
        $params[$name] = $value;
      }
    }
    if ($contact_id) {
      $params['contact_id'] = $contact_id;
    }
    $result = civicrm_api3('Profile', 'submit', $params);
    if (!empty($result['id'])) {
      switch ($entity_type) {
        case 'contact':
          $contact = entity_load_single('civicrm_contact', $result['id']);
          return $contact;
        case 'participant':
          if (!empty($result['values'][$contact_id]['api.participant.create']['id'])) {
            $participant = entity_load_single('civicrm_participant', $result['values'][$contact_id]['api.participant.create']['id']);
            return $participant;
          }
          else {
            return FALSE;
          }
      }
    }
    else {
      return FALSE;
    }
  } catch (CiviCRM_API3_Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'warning');
    return FALSE;
  }
}