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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:20:08+00:00 2026-05-13T23:20:08+00:00

I have a site where some users will be registered by our staff, and

  • 0

I have a site where some users will be registered by our staff, and won’t have emails associated with them. I would like to keep the email field a required field, so I devised a random email generator.

 function generateRandomEmail() {
     $email = 'noemail'. rand(0,1000000) . '@noemail.com';
     return $email;
  }

So, I attached that to the user register form alter, and it worked nicely, effectively generating an email for these users.

However, in the process, all the other fields associated with the main account section (password, username, notify, etc.) disappeared. My question, is there a quick way to populate the rest of the fields that I don’t want to alter? I’ve used drupal_render($form); in a tpl.php, but it didn’t work in the form alter.

Here is where I’m altering the form:

  function accountselect_user($op, &$edit, &$account, $category) {
    if ($op == 'register') {

       $fields['account']['mail'] = array(
       '#type' => 'textfield',
       '#default_value' => generateRandomEmail(),
    );
  • 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-13T23:20:09+00:00Added an answer on May 13, 2026 at 11:20 pm

    You are currently using hook_user for your manipulation, but that is the wrong place. On $op ‘registration’, you can return additional fields you want to inject to the registration process, but not alter existing fields. Use hook_form_alter() or hook_form_FORM_ID_alter() for that, e.g.:

    function yourModule_form_user_register_alter(&$form, &$form_state) {
      $form['account']['mail']['#default_value'] = generateRandomEmail();
    }
    

    You probably want to add a check that the request is in fact coming from the staff, since the above code would prepopulate the email field for the normal registration form also!


    Also, please do not generate ‘random’ mail addresses using existing third party domains (like ‘nomail.com’). Use the reserved ‘example.com’, or better yet, one that you own yourself!

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

Sidebar

Related Questions

We have a site that is serving some RSS feeds, and we'd like to
My site has urls like 'http://someRandomUsername.mysite.com'. Sometimes users will try urls like 'http://www.someRandomeUsername.mysite.com'. I'd
I have textarea in my site(link shortening site) i want to user enter some
I have some site where I am embedding a couple of youtube videos in
I have public site with some forms. Simple question: What kind of informations should
I have a site that features some pages which do not require any post-back
In my site there have some mailing options.Here iam sending an html mails. So
I have a local mercurial repository with some site-specific changes in it. What I
Some site I'm programming is using both ASP.NET MVC and WebForms. I have a
I'm have a form set up which allows users to register with our mobile

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.