access profile2 fields values How can I access fields values inside profile2 main profile? Only on edit main profile page? I try to hide a field on profile2 edit page based on another value. Code is from my template.php 

function my_theme_form_profile2_edit_main_form_alter


and then calling

global $user;
$profile = profile2_load_by_user($user-&gt;uid, 'main');
$checkbox1 = $profile-&gt;field_checkbox_admin1['und'][0]['value'];


The problem is that profile variable is not accessible if all of the fields in profile are empty. dpm($profile) shows nothing and I get undefined variable error.
Just define the  variable already before using it 

$profile ="";
global $user;
$profile = profile2_load_by_user($user-&gt;uid, 'main');
$checkbox1 = isseet($profile-&gt;field_checkbox_admin1['und'][0]['value']) ?      $profile-&gt;field_checkbox_admin1['und'][0]['value'] : "";


That is nature the profile 2 module, it doesn't create any entry for any field in the database untill it is not assigned any value actually. So it returns nothing if it is empty.

Hope it will help