There's an issue with Profile2 compatibility, specifically the way Profile2 handles forms. When changing the country field on certain Profile2 forms, ajax doesn't update the form. This is due to the following PHP error.

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'profile2_form' not found or invalid function name in drupal_retrieve_form() (line 798 of /includes/form.inc).

By adding a module include for Profile2 in the addressfield.module it appears to fix this. However this approach seems like the proverbial using a "sledgehammer to crack a nut."

<?php
/**
 * Implements hook_init().
 */
function addressfield_init(){
  if(module_exists('profile2')){
    module_load_include('inc', 'profile2', 'contrib/profile2_page');
  }
}?>

The setup was as follows: I had a Profile2 form with an addressfield in it. When I included the form using the Profile2 approach of "attaching" forms, the ajax changing generated the above error.

Comments

rszrama’s picture

Title: Profile2 Compatibility Fix » Issue rebuilding the form on an Address Field AJAX refresh
Project: Address Field » Profile2
Version: 7.x-1.0-beta3 »

As you guessed, this isn't an appropriate fix for Address Field. If I read you right, Profile2 should instead be ensuring its form's build_info array points to the appropriate include file to load when the form gets rebuilt (as it does during this AJAX update request). See for example this code in commerce_product.forms.inc:

  // Ensure this include file is loaded when the form is rebuilt from the cache.
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'commerce_product') . '/includes/commerce_product.forms.inc';

Moving this to the Profile2 queue in case it's still an issue. Feel free to close out if you guys already have a fix for this.

rszrama’s picture

Title: Issue rebuilding the form on an Address Field AJAX refresh » Cannot rebuild the form on an Address Field AJAX refresh
Project: Profile2 » Profile 2
Version: » 7.x-1.x-dev

Holy crap, that Profile2 sandbox title is very confusing in the issue tracker. : P