Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 431009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:55:55+00:00 2026-05-12T19:55:55+00:00

Trying to prepopulate some of my form fields, and am using hook_form_alter(). I’ve tried

  • 0

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);

        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:55:55+00:00Added an answer on May 12, 2026 at 7:55 pm

    You are missing one array level. The profile form fields will not be at the top level in the $form array, but in a subarray keyed by the category name. So if you assigned your fields a category of ‘example category’, your code should look like this:

    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['example category']['profile_company_site']['#default_value'] = $user->profile_company_site);
                $form['example category']['profile_blog_url']['#default_value'] = $user->profile_blog_url);
                $form['example category']['profile_my_website_url']['#default_value'] = $user->profile_my_website_url);
                $form['example category']['profile_first_name']['#default_value'] = $user->profile_first_name);
                $form['example category']['profile_last_name']['#default_value'] = $user->profile_last_name);
            }
        }
    }
    

    You should use a debugger (or at least a var_dump()) to inspect the form array you want to manipulate – saves a lot of time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 237k
  • Answers 237k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Floating point values certainly can be equal to each other,… May 13, 2026 at 6:33 am
  • Editorial Team
    Editorial Team added an answer Ajax version would have to use something on the server… May 13, 2026 at 6:33 am
  • Editorial Team
    Editorial Team added an answer What about using a temporary session variable? On your first… May 13, 2026 at 6:33 am

Related Questions

Trying to prepopulate some of my form fields, and am using hook_form_alter(). I've tried
I have made a function that connects to a models 'pre_save' signal. Inside the
I am trying to make saving and loading easier for some GUIs that I've
I am a noob and am trying to get my head around TG2 and
Is there an easy way to have a rails action load up an external

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.