I need my drupal installation to have multiple registration pages with different fields on each. Here is my plan:

1.) Create profile fields that are visible on the registration pages.

2.) Create several alias urls for the registration page.

3.) Develop a hook that determines the alias with the arg() function, and then adjusts the register form accordingly by removing certian fields.

It's this third step that I'm not sure how to proceed with. I'm new to module development. Can anyone let me know which hook I should use for this? As much information as possible, please!

I should mention that the situation if complicated further because I am using the logintoboggan module (or maybe that will simplify things). Can I modify logintoboggan.module to make this work?

Thanks,

Moses

Comments

jasonwhat’s picture

I'm no expert on how this would be done, but it seems that using some mashup of jquery/ajax would be better than separating into different pages. To the user they will seem to go to a new screen, but it could just be a matter of loading separate page elements as they go. The one trick with this would be saving data at each step rather than on the final one.

Option 2 could be to use the implementations of CCK and nodes as profiles kicking around CVS.

flamingvan’s picture

You're giving me an idea. I could make custom register pages that post to a reflector page that then posts to drupal. The reflector page could fill in the missing fields with "no field" or some other string.

What is CCK?

Thanks!

Anonymous’s picture

Is there anything new with this problem ?

I saw at least 15 posts on this forum about people wanting to have multiple registration pages, depending on the role the user has chosen to sign up.

The Role signup module has totally no interest if it's impossible to redirect the user to a form for each role.

I'm waiting for a solution to put my website online.

Any help would ben appreciated ;)

Thank you

Anonymous’s picture

Is it possible to hard code a registration form ?

j.patrick1982’s picture

I need same do you have solution

benalexander’s picture

Hi guys,

I've also been looking at ways to do this, and found a possible way to do it using the form's #pre_render attribute - with the help of the excellent Pro Drupal book :-)

Not sure if this is the best way to do this or what, but thought I'd share it anyway and get your thoughts.

1. Create the fields using profile.module
2. Add the following code in a custom module - an implementation of hook_form_alter and a function to actually alter the form:


<?php
function mymodule_form_alter($form_id, &$form) {
  switch($form_id){
    // check which type of form is being built
    case "user_register":
      //assume the path is '/user/register/blogger'
      if(arg(2) == "blogger")
      {
       $form['#pre_render'] = array('mymodule_remove_fields');
      }
    return;
  }
}

function mymodule_remove_fields($form_id, &$form){
  //to remove a whole category
  unset($form['My category']);
  //to remove a single field
  unset($form['My other category']['profile_myfield']);
}
?>

#pre_render is basically an array of functions to call just before the form is rendered as html.

One caveat is that I don't think the fields can be required if you do this as profile.module will attempt to validate them every time - I think you would have to add some extra valdation code using hook_user and test decide what to do using arg() again.

You could also remove the field by implementing hook_user, in the 'form' operation part of it - but this would depend on your module's hook being called after profile.module's, and I'm not sure what determines the order (it may just be alphabetical).

Hope this is of some help - I'm reasonably new to Drupal so if anyone with more experience has some feedback on this, that would be great.

Ben

jowan’s picture

ben, I think the above method would work for me really well as i just want to hide a few fields that are optional anyway.
Alas i can't get it to work. Could you please help me.
I made a new module and enabled it
I have a few roles one of which is 'artist' and a profile category called 'personal'
but it doesn't work for me when i fill in these details in your code.
I also have the rolesignup module installed and this too has a prerender function on the form, could this be conflicting or something.
If so, when i uninstall the rolesignup module and register as a new user, how do i set which type of role is being registerd for to make the path and the arg(2) my role?

thanks

jowan’s picture

ok, i figured it out, probably a bit of a bodge job
rolesignup module places a value in a session variable, this is a number representig the roleid, you can get what the number is for each role form yuor database
the roleid for my role 'artist' was three so i used the following code

<?php

function testmod_form_alter($form_id, &$form) {
  if ($form_id == "user_register") {
    global $user;
    if (!user_access('administer users') ) {
       if ($_SESSION['role'] == 3) {
      $form['#pre_render'] = array('mymodule_remove_fields');
	  } 
    return;
  }
}
}

function mymodule_remove_fields($form_id, &$form){
  //to remove a whole category
  unset($form['Personal information']);
}

this way it can be used in conjunction with roleonsignup module