You are here

function webform_civicrm_state_abbr in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm_utils.inc \webform_civicrm_state_abbr()

Match a state/province id to its abbr. and vice-versa

3 calls to webform_civicrm_state_abbr()
webform_civicrm_process_submission in ./webform_civicrm_forms.inc
Webform submission handler Create/update CiviCRM contacts and related data Called by presave, insert and update webform hooks
webform_civicrm_update_6203 in ./webform_civicrm.install
Support new state/prov chain-select feature.
_webform_civicrm_webform_frontend_form_alter in ./webform_civicrm_forms.inc
Alter front-end of webforms: Called by hook_form_alter() when rendering a civicrm-enabled webform Add custom prefix. Display messages. Block users who should not have access. Set webform default values.

File

./webform_civicrm_utils.inc, line 422
Webform CiviCRM module's common utility functions. The code in this file is cross-compatible with D6/Civi3 and D7/Civi4 Drupal-version-specific functions belong in webform_civicrm_dx_functions.inc

Code

function webform_civicrm_state_abbr($input, $ret = 'abbreviation', $country_id = NULL) {
  $input_type = $ret == 'id' ? 'abbreviation' : 'id';
  $sql = "SELECT {$ret} FROM civicrm_state_province WHERE {$input_type} = %1";
  $vars = array(
    1 => array(
      $input,
      $ret == 'id' ? 'String' : 'Integer',
    ),
  );
  if ($country_id) {
    $sql .= ' AND country_id = %2';
    $vars[2] = array(
      $country_id,
      'Integer',
    );
  }
  $sql .= ' LIMIT 0, 1';
  return CRM_Core_DAO::singleValueQuery($sql, $vars);
}