Trying to prepopulate some of my form fields, and am using hook_form_alter(). I've tried a couple of different ways, but in both cases, the fields still come up empty. I'm assuming that I need to set default_value and not value because if the user changes what's in the field, I want that to update correctly. Is that right?
Here's what I've been trying:
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'user_profile_form') {
if(arg(0) == 'user' && arg(1)) {
$user = user_load(arg(1));
$form['profile_company_site']= array('#default_value' => $user->profile_company_site);
$form['profile_blog_url']= array('#default_value' => $user->profile_blog_url);
$form['profile_my_website_url']= array('#default_value' => $user->profile_my_website_url);
$form['profile_first_name']= array('#default_value' => $user->profile_first_name);
$form['profile_last_name']= array('#default_value' => $user->profile_last_name);
}
}
}
I also tried it this way:
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'user_profile_form') {
if(arg(0) == 'user' && arg(1)) {
$user = user_load(arg(1));
$form['profile_company_site'][#default_value'] = $user->profile_company_site);
$form['profile_blog_url'][#default_value'] = $user->profile_blog_url);
$form['profile_my_website_url']['#default_value'] = $user->profile_my_website_url);
$form['profile_first_name']['#default_value'] = $user->profile_first_name);
$form['profile_last_name']['#default_value'] = $user->profile_last_name);
}
}
}