just photo

Drupal 6. Disable mail field on the user account page

Julia 08/06/2010

If you need to make email field disabled, it won't be anough just make it #disabled.
You have to add the same hidden field:

<?php
function [modulename]_form_alter(&$form, $form_state, $form_id) {
    global
$user;

  switch (
$form_id) {
      case
'user_profile_form':
          if (
$user->uid != 1){
         
// fields must have a hidden field w/ proper value as disabled fields are not submitted.
       
$form['account']['readonly']['mail'] = $form['account']['mail'];
       
$form['account']['readonly']['mail']['#type'] = 'hidden';
           
$form['account']['mail']['#disabled'] = TRUE;
          }
          break;
  }
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options