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 6906093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:15:57+00:00 2026-05-27T08:15:57+00:00

I’m trying to override the user profile edit form in Drupal 7, and I

  • 0

I’m trying to override the user profile edit form in Drupal 7, and I keep on getting the following error messages:

Notice: Undefined index: #account in template_preprocess_user_profile() (line 189 of /var/www/menit/modules/user/user.pages.inc).
Notice: Undefined index: #account in rdf_preprocess_user_profile() (line 578 of /var/www/menit/modules/rdf/rdf.module).
Notice: Trying to get property of non-object in user_uri() (line 190 of /var/www/menit/modules/user/user.module).
Notice: Trying to get property of non-object in rdf_preprocess_user_profile() (line 603 of /var/www/menit/modules/rdf/rdf.module).
Notice: Trying to get property of non-object in rdf_preprocess_user_profile() (line 604 of /var/www/menit/modules/rdf/rdf.module).

What I have done is writing a custom module, containing the following code:

function custom_profile_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  global $user;

  if ($user->uid != 1){
    $form['#theme'] = 'user_profile';
  }
}

function menit_theme($existing, $type, $theme, $path){
  return array(
    'user_profile' => array(
      'render element' => 'form',
      'template' => 'templates/user_profile',
    ),
  );
}

and added the following user_profile.tpl.theme to my theme templates folder:

<div class="profile"<?php print $attributes; ?>>
  <?php print render($user_profile['field_second_name']);  ?>
  <?php print render($user_profile['field_first_name']);?>
  <?php print render($user_profile);?>
</div>

I’m kind of lost now, and I’m running short on time. Does anyone have an idea of what have I done wrong here?

  • 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-27T08:15:57+00:00Added an answer on May 27, 2026 at 8:15 am

    The problem is the following line you are using:

    $form['#theme'] = 'user_profile';
    

    That lines changes the theme function associated to the form, and it is causing some preprocess functions to be invoked, such as [template_preprocess_user_profile()][1], and [rdf_preprocess_user_profile()][2]. All those preprocess functions, which are thought to be called for user profile, are looking for some variables that in your case are not defined, such as $variables['elements']['#account'].

    You don’t use a template file to render a form. Depending what you want to achieve, you can use different methods:

    • If you want to remove some form fields, you implement hook_form_FORM_ID_alter(), which is the hook you have already implemented, and use it to hide some form fields.

      $form[$field_id]['#access'] = FALSE;
      

      In this way, the field will not shown for the user. I suggest using that, as it is the method that causes less problem to other modules than unset($form[$field_id]); if you use this, $form_state['values'] will not contain the values for that field, and some validation, or submission handler could report an error (e.g. “the value for [name of the field] must be entered”).

    • If you want to add a CSS class to a form field, you can use:

      $form[$field_id]['#prefix'] = '<div class="mymodule-custom-class">';
      $form[$field_id]['#suffix'] = '</div>';
      

      This is the simpler, and faster way. If you need to wrap more than one form field, then you should use something similar to the following code:

      $form[$field_id1]['#prefix'] = '<div class="mymodule-custom-class">';
      $form[$field_id2]['#suffix'] = '</div>';
      

      In such cases, you normally want to add a CSS style to the form, which is done with code similar to the following one:

      $form['#attached']['css'][] = drupal_get_path('module', 'mymodule') . '/mymodule.css';
      

      You could also move the form fields in a #container form field, as with the following code:

      $form['container_01'] = array(
        '#type' => 'container',
        '#attributes' => array(
          'class' => array('mymodule-custom-class'),
        ),          
      );
      
      $form['container_01'][$field_id] = $form[$field_id];
      
      unset($form[$field_id]);
      

      In this case, the form field will be wrapped with a <div> tag with the CSS class set for the container. The con with this is that the fields are moved from where they were; you need to adjust their weight to make then appear where they were before. If you use this method, you should be sure your module is the last one to change the form, or modules that expect to find $form[$field_id] will have some problems; this doesn’t apply to the form handlers, except when $form[$field_id]['#tree'] is set to TRUE.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.