--- cck_address.module 2007-05-09 17:50:40.000000000 -0700 +++ cck_address.module.new 2007-05-10 19:36:59.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.2 2007/05/10 00:50:40 rconstantine Exp $; + * @version $Id: cck_address.module,v 1.1.1.1.2.2 2007/05/10 05:29:54 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( @@ -311,12 +318,9 @@ function cck_address_field($op, &$node, $errors['country'] = t('Illegal value for %name\'s Country field. You must select a Country from the dropdown list.', array('%name' => t($field['widget']['label']))); } $state_options = cck_address_get_states($selected_country); - if (!array_key_exists($item['state'], $state_options)) { + if (!$field['other_countries'] && !array_key_exists($item['state'], $state_options)) { $errors['state'] = t('Illegal value for %name\'s State field. You must select a State from the dropdown list.', array('%name' => t($field['widget']['label']))); } - /*if (($item['state'] != '') && (!preg_match("/^[A-Za-z\s]+$/", $item['state']))) { - $errors['state'] = t('Illegal value for %name\'s State field. No numbers or special characters allowed.', array('%name' => t($field['widget']['label']))); - }*/ //pass all other fields on to the various address modules for validation foreach (module_implements('validate_address_fields') as $name) { @@ -517,7 +521,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']); @@ -751,6 +760,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' => '