0

So I have created a drupal multisite install with a shared user database and I would like to store the site the user has signed up on.

I have also created a view of user and I would like to filter them by site. Ideally I would like the view filter to be a dropdown, but it isn't essential.

I am already overriding the user_register_form via the template.php file, would it best to create a new text field for the user then hide and set it to the current domain via the template.php file?

1

Hope this will help you,

In Drupal 7

The best way to do is to create a new field for user registration form. Lets call the field as domain.

Steps:

  1. Go to admin/config + Account settings + Manage Fields
  2. Add new field enter image description here After adding enter image description here If you want to show this field in registration then check this enter image description here

    NOTE: If prefer do not show on registration form. May be there a chance to edit. Even though if your making it as disable, it can be change.

    When ever the user registration form load, alter the form using hook_form_alter and give the default value for it.

    function mymodule_form_alter(&$form, $form_state, $form_id)  {
    switch ($form_id)  {
        case 'user_register_form':
           //get field language
           $field_lang = field_language('user', 'field_user_domain');
           //assign default value
           $form['field_user_domain'][$field_lang['field_user_domain']][0]['#default_value'] = $_SERVER['HTTP_HOST'];
        break;
     }
    }
    
    When ever the users register the domain also saved.

You can use this field in views as per your requirement.

  • This is perfect! Thank you for your very clear explanation this is exactly what I needed. Thanks again :) – JordanW Jul 1 '13 at 14:00
  • Welcome :) enjoy coding – inizio Jul 1 '13 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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