--- cck_address.module 2007-05-09 17:43:01.000000000 -0700 +++ cck_address.module.new 2007-05-09 17:48:21.000000000 -0700 @@ -10,7 +10,7 @@ * set by the admin. State is a dropdown list with values supplied via a database table * which is part of this module. ZIP is a 5 digit integer field.

* - * @version $Id: cck_address.module,v 1.1.2.1 2007/04/11 23:24:30 rconstantine Exp $; + * @version $Id: cck_address.module,v 1.1.1.1.2.1 2007/05/09 00:48:19 russ Exp $; * @package CCK * @category CCK * @author Ryan Constantine @@ -89,10 +89,10 @@ function cck_address_field_settings($op, case 'form': $form = array(); $form['state_abbrv'] = array( - '#type' => 'checkbox', - '#title' => t('Use abbreviations for display of States/Provinces?'), + '#type' => 'select', + '#title' => t('Display States/Provinces as'), '#default_value' => isset($field['state_abbrv']) ? $field['state_abbrv'] : 0, - '#return_value' => 1, + '#options' => array('Select with full names', 'Select with abbreviations', 'Free-text entry'), ); $form['country_abbrv'] = array( '#type' => 'checkbox', @@ -113,6 +113,13 @@ function cck_address_field_settings($op, while ($result = db_fetch_object($results)) { $all_countries[$result->country_code] = $result->country_name; } + $form['countries']['other_countries'] = array( + '#type' => 'checkbox', + '#title' => t('Allow "other" countries?'), + '#description' => t('Disable validation of state field against the state database. Admin users should validate the state field of sumitted addresses manually.'), + '#default_value' => isset($field['other_countries']) ? $field['other_countries'] : 0, + '#return_value' => 1, + ); $form['countries']['clist'] = array( '#type' => 'checkboxes', '#title' => t('Countries'), @@ -181,7 +188,7 @@ function cck_address_field_settings($op, break; case 'save': - return array('state_abbrv', 'country_abbrv', 'clist', 'max_length_street1', 'max_length_street2', 'max_length_city', 'max_length_other'); + return array('state_abbrv', 'country_abbrv', 'clist', 'max_length_street1', 'max_length_street2', 'max_length_city', 'max_length_other', 'other_countries'); case 'database columns': $columns = array( @@ -321,6 +328,10 @@ function cck_address_field($op, &$node, form_set_error($error_field_country, t('Illegal value for %name\'s Country field. You must select a Country from the dropdown list.', array('%name' => t($field['widget']['label'])))); } + if ($field['other_countries']) { + $selected_state[$item['state']] = $item['state']; + } + else { $state_options = cck_address_get_states($selected_country); if (array_key_exists($item['state'], $state_options)) { $selected_state[$item['state']] = $item['state']; @@ -330,6 +341,7 @@ function cck_address_field($op, &$node, } } } + } if ($field['max_lengths']['max_length_street1'] > 0) { foreach ($items as $delta => $data) {//again, don't know if we'll ever need to deal with multiples, but leaving this in just in case $error_field_street1 = $field['field_name_street1'].']['.$delta.'][street1'; @@ -419,7 +431,12 @@ function cck_address_format($field, $ite $allowed_countries[$code] = $all_countries[$code]; } $country[$item['country']] = $all_countries[$item['country']]; + + if ($field['state_abbrv'] == 2) { + $cck_address_state = strip_tags($item['state']); + } else { $states = cck_address_get_states($country); + } //check the values $cck_address_street1 = strip_tags($item['street1']); @@ -653,6 +670,21 @@ function cck_address_widget($op, &$node, $state = isset($_POST[$field['field_name']][0]['state']) ? $_POST[$field['field_name']][0]['state'] : $items[0]['state']; + if ($field['state_abbrv'] == 2) { + + $form[$field['field_name']][0]['state'] = array( + '#type' => 'textfield', + '#title' => t('State'), + '#default_value' => $state, + '#required' => $field['required'], + '#size' => $field['max_length_other'] ? $field['max_length_other'] : NULL, + '#maxlength' => $field['max_length_other'] ? $field['max_length_other'] : NULL, + '#prefix' => '
', + '#suffix' => '
', + ); + $form[$field['field_name']][0]['state']['#attributes'] = $field['max_length_other'] ? array('style' => 'width:' .$field["max_length_other"]*0.85. 'em') : array(); + } + else { $form[$field['field_name']][0]['state'] = array( '#type' => 'select', '#title' => t('State'), @@ -665,6 +697,17 @@ function cck_address_widget($op, &$node, '#DANGEROUS_SKIP_CHECK' => TRUE, ); + if ($activeselect) { + $form[$field['field_name']][0]['country']['#type'] = 'activeselect'; + $form[$field['field_name']][0]['country']['#activeselect_path'] = 'cck_address/activeselect'; + $form[$field['field_name']][0]['country']['#activeselect_targets'] = str_replace('_', '-', $field['field_name']). '-0-state'; + $form[$field['field_name']][0]['country']['#activeselect_extra'] = $state; + } + else { + $form[$field['field_name']][0]['state']['#options'] = $state_options; + } + } + $form[$field['field_name']][0]['zip'] = array( '#type' => 'textfield', '#title' => t('ZIP'), @@ -690,16 +733,6 @@ function cck_address_widget($op, &$node, '#suffix' => '', ); - if ($activeselect) { - $form[$field['field_name']][0]['country']['#type'] = 'activeselect'; - $form[$field['field_name']][0]['country']['#activeselect_path'] = 'cck_address/activeselect'; - $form[$field['field_name']][0]['country']['#activeselect_targets'] = str_replace('_', '-', $field['field_name']). '-0-state'; - $form[$field['field_name']][0]['country']['#activeselect_extra'] = $state; - } - else { - $form[$field['field_name']][0]['state']['#options'] = $state_options; - } - $form[$field['field_name']][0]['other'] = array( '#type' => 'textfield', '#title' => t('Other'),