0

I thought this would be straight forward but my lack of drupal knowledge is holing me back. I want to grab the email from the logged in user, and set it as the default value of the form. I can grab the email from the global user logged in, but cannot pass this to the form?

The email field is blank, but I have the email stored in $email1 I want to place this value in the text box, as the default field.

global $user;
    $user_full = user_load($user->uid); 
    $email1= $user_full ->mail;
    echo $email1;

 $form['admin_email'] = array (
 '#type' => 'textfield',
 '#title' => t('Admin Email need email validation!!!'),
 '#description' => t('Please enter an Email'),
 '#default_value' => $user_full->mail,
 );
2
  • 1
    And? What's are the effects? PHP error? Form field empty by default? Something within Watchdog?..
    – Mołot
    Commented Sep 13, 2013 at 13:33
  • Sorry i just get a blank field @Mołot
    – Tom
    Commented Sep 13, 2013 at 13:50

1 Answer 1

0

You don't need to use user_load($user->uid);. You already have a complete object inside global $user; variable. And don't forget PHP is not a natural languages. You can't just put whitespaces where you want them. In method call or property access, there should be no spaces around ->, it should be right next to object, and property should be right after arrow.

This line is sufficient for me:

'#default_value' => $user->mail,
3
  • @Tom please edit your question and address concerns from my comment, OK? Now it's a bit unclear what's your problem, exactly.
    – Mołot
    Commented Sep 13, 2013 at 13:46
  • The reason I was using the uid was because, i have custom profile fields that i want to add to the form fields. I read that to pull these I had to have the code as above rather than just global $user?
    – Tom
    Commented Sep 13, 2013 at 13:51
  • @tom if you want to use custom fields, ask about custom fields in your question. mail is a built in field. We cannot help you if you don't want to tell us what exactly are you doing.
    – Mołot
    Commented Sep 13, 2013 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.