Customized registration forms

Websites are making themselves better and better to attract more user registrations. Recently I was working on a project with four different types of registration blocks appearing in various ways when anonymous users were looking around the site. I tried to use webform and a contrib module that stated it could turn a normal webform into a register form. But it didn’t work at all. So I would like instead to show a different approach on how to customize the registration form.

First, to call the default register block which could be found under “/user/register”, we use drupal_get_form(‘user_register’) and then print. It prints the same form as /user/register. You can find background setting for the default form under /admin/user/settings indicating auto-generated password for new users, feedback email after they registered and many other variables. If you go to admin/user/profile, you can set additional fields and information to be collected during registration process, for example company name, full name and etc.

In addition, if you are looking for Captcha, registration questions or invitation code, you can probably turn to other contrib modules.

Steps mentioned above can make your registration form different from other sites. But to make different registration form among different pages on your site, you need to write your own custom module. In this case, I’m using form_alter hook to change the default fields when form_id == ‘user_register’.

Set up conditions before changing the form. For example if $node->type == “article”, then print form in array with names and emails. This step makes the registration form generated with style you want and it keeps the original one under /user/register same as before. You can dump and check the default one to see if you need something like #element_validate and #required.

After that is done, everything is under your complete control, including form elements and validation process. You further could play with cookie checks to popup the registration form on different pages using different styles.

Leave a comment

Your email address will not be published. Required fields are marked *