I'm trying to pre-populate a field in a new piece of content with a country field from a users profile. These are two different Drupal fields, but they are both using the location module so country codes should easily transferred between the two.
I have managed to verify the data from $field_country_you_co_ordinate_fo['und'][0]['country']), this prints the country code 'gb' as expected.
I can't pull the value into $form['field_location']. Tried several different chains of array keys based on the previous ticket linked at the bottom. I'm clearly misunderstanding the combinations of keys needed to pull from one variable to another, so any help would be greatly appreciated.
Thanks in advance
function perma_boot_form_organisation_node_form_alter(&$form, &$form_state, $form_id) {
// Only run against newly created node
if (empty($form['nid']['#value']) && (!isset($form['#node']->op))) {
global $user;
$user_fields = user_load($user->uid);
if (isset($user_fields->field_country_you_co_ordinate_fo['und'][0]['country'])) {
//print_r ($user_fields->field_country_you_co_ordinate_fo['und'][0]['country']);
$form['field_location']['und'][0]['country'] = $user_fields->field_country_you_co_ordinate_fo['und'][0]['country'];
}
}
}
Have been working from the previous example: How to pre-populate fields on a node creation form based on fields from Profile2 module?
$form
array no? Then you will probably see that you're simply misunderstanding the array structure and putting the value in the wrong place. (I think you're missing the#address
element of the array:$form['field_location']['und'][0]['#address']['country']
)$form['field_location'][LANGUAGE_NONE][0]['country]['#default_value']
if you are indeed prepopulating with a default value. Cheers -