Add role on custom register form I'm using the default register form on a custom page, which I want to use to set a specific role for the user who registers using that custom page.

Now I need to know how I add this specific role when the user registers.

Can I use like, the submit funcion for the custom form function, and then use user_multiple_role_edit()?

But how di I get the $uid?

What's best?
Here is my solution based on my favorite Rules module ;)

These 2 rules below automatically assign a predefined role to a user who registers to your website using a promotional link and code.

Important: Before importing these 2 rules:


backup your site :P 
replace example.com with your domain name
replace 11 with your role id number
replace code=promo1 with your secret promotional code


You can import rules via this page on your website:
/admin/config/workflow/rules/reaction/import

Rule 1:

{ "rules_auto_assign_role_1" : {
    "LABEL" : "Auto assign role to user based on the registration path Part 1",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "user_presave" ],
    "IF" : [
      { "NOT user_has_role" : { "account" : [ "account" ], "roles" : { "value" : { "11" : "11" } } } },
      { "data_is" : {
          "data" : [ "site:current-page:url" ],
          "value" : "http:\/\/example.com\/user\/register?code=promo1"
        }
      }
    ],
    "DO" : [ { "redirect" : { "url" : "user?code=promo1" } } ]
  }
}


Rule 2:

{ "rules_auto_assign_role_2" : {
    "LABEL" : "Auto assign role to user based on the registration path Part 2",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "user_view" ],
    "IF" : [
      { "AND" : [
          { "NOT user_has_role" : {
              "account" : [ "site:current-user" ],
              "roles" : { "value" : { "11" : "11" } }
            }
          },
          { "data_is" : {
              "data" : [ "site:current-page:url" ],
              "value" : "http:\/\/example.com\/user?code=promo1"
            }
          }
        ]
      }
    ],
    "DO" : [
      { "user_add_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "11" : "11" } }
        }
      }
    ]
  }
}