User login

dump of data and notes running in circles trying to make addressfield not force a value for country on optional fields

in

UPDATE: Patch to Addressfield in need of review: http://drupal.org/node/968112

WRONG:

/**
* Implements hook_form_alter().
*
* The sledgehammer approach to telling Addressfield not to have a default.
*/
function feature_projects_form_alter(&$form, $form_state, $form_id) {
if (isset

RIGHT:

  • Tell Addressfield not to have a default country.
    */
    function feature_projects_element_info_alter(&$type) {
    debug($type, "Type", TRUE);
    // if (isset($type[
    }

http://drupal.org/node/224333#hook_element_info

Removing the US from here didn't help either.

a:7:{s:13:"default_value";a:1:{i:0;a:8:{s:19:"administrative_area";s:0:"";s:7:"country";s:2:"US";s:11:"element_key";s:32:"node|project|field_address|und|0";s:8:"locality";s:0:"";s:17:"organisation_name";s:0:"";s:11:"postal_code";s:0:"";s:7:"premise";s:0:"";s:12:"thoroughfare";s:0:"";}}s:11:"description";s:0:"";s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:6:"module";s:12:"addressfield";s:8:"settings";a:2:{s:15:"format_handlers";a:1:{i:0;s:7:"address";}s:19:"use_widget_handlers";i:1;}s:4:"type";s:20:"addressfield_default";s:6:"weight";s:1:"5";}s:6:"teaser";a:4:{s:5:"label";s:5:"above";s:8:"settings";a:0:{}s:4:"type";s:6:"hidden";s:6:"weight";s:2:"29";}}s:5:"label";s:7:"Address";s:8:"required";i:0;s:8:"settings";a:1:{s:18:"user_register_form";b:0;}s:6:"widget";a:5:{s:6:"active";i:1;s:6:"module";s:12:"addressfield";s:8:"settings";a:2:{s:19:"available_countries";a:0:{}s:15:"format_handlers";a:4:{s:7:"address";s:7:"address";s:9:"name-full";i:0;s:12:"name-oneline";i:0;s:12:"organisation";s:12:"organisation";}}s:4:"type";s:21:"addressfield_standard";s:6:"weight";s:1:"6";}}

drupal 7 change form element value on validate

in addressfield module, this works beautifully to show what's up:

/**
* Implements hook_field_validate().
/
function addressfield_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
debug($items);
/

foreach ($items as $delta => $value) {
_link_validate($items[$delta], $delta, $field, $entity, $instance, $optional_field_found);
}
*/
}

in addressfield_field_validate() (line 757 of /home/ben/code/sdl/web/sites/all/modules/contrib/addressfield/addressfield.module).
Debug:

array (
0 =>
array (
'element_key' => 'node|project|field_client_address|und|0',
'thoroughfare' => '',
'premise' => '',
'locality' => '',
'administrative_area' => '',
'postal_code' => '',
'country' => 'US',
'first_name' => '',
'last_name' => '',
'organisation_name' => '',
),
)

Searched words: 
drupal addressfield should not provide default country hook_element_info_alter validate drupal 7 find form element

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.