I have two location fields created in my Drupal site, $field_location in the node and $field_organisations_role_in_coun which is associated with the user profile. My plan was to take the country field from the users location field and pull that into a node at the point of creation.

The following code in my themes template.php and it appears to work. I have devel running and I can seen the values have been populated to the field. However, this causes the location field to disappear and google map to break. I'm a little stumped as I can't see any error messages printed on the server or locally.

if (empty($form['nid']['#value']) && (!isset($form['#node']->op))) {
	global $user;
	$user_fields = user_load($user->uid);
	// If location is set for user pull value to node
	if (isset($user_fields->field_country_you_co_ordinate_fo['und'][0]['country'])) {
		// Pre populate country field in node with value from users profile
		$form['field_location']['und'][0]['country']['#value'] = $user_fields->field_country_you_co_ordinate_fo['und'][0]['country'];		
	}
}

Comments

fyberoptik created an issue.