开发者

Customizing Drupal user account form

开发者 https://www.devze.com 2022-12-22 12:20 出处:网络
In my Drupal Site, i will be having two categories of users,say Category A and Category B. When a person wants to create an account on the site, i want to ask开发者_开发百科 them which category they b

In my Drupal Site, i will be having two categories of users,say Category A and Category B. When a person wants to create an account on the site, i want to ask开发者_开发百科 them which category they belong to and based on that show the fields on the User Account Form. The fields shown depend on the category selected. The Drupal user account form has two fields by default i.e. username and email and i can add more by using the Profile module, but how to show different set of fields on the user account form depending on the users selection ?

Any help would be greatly appreciated. Thank You


Check the Profile Setup module. Some more details about this module (from its project page):

Profile setup for Drupal 6 now works along side the pageroute module (6.x-1.x-dev) to provide additional page types via the pageroute API, so completely custom profile setup workflows are now more flexible than ever thanks to the help of the pageroute module.

Full setup instructions are given in the INSTALL.txt file in the module folder, so please READ THEM BEFORE YOU INSTALL THIS MODULE or consider submitting a bug report.

If you are upgrading from the Drupal 5 version please read the UPGRADE.txt file in the module folder.


I've done this in the past with hook_form_alter and checking $_GET['type']. If $_GET['type'] is empty, I did something like this:

$form = array(
  '#value' => '<div><a href="/user/register?type=A">Register as A</a> or <a href="/user/register?type=B">Register as B</a></div>',
);

If $_GET['type'] is 'A' or 'B', I removed the irrelevant form elements for that type. Then in the #submit handler, I put the user in the appropriate role.


Also check out:

http://drupal.org/project/profile_role

http://drupal.org/project/autoassignrole


by using hook_form_alter you can change your form fields, using unset and add a element inside form. I assume that you have a category selection on the same user register page upon selection you can use AHAH Helper module to change form field based on category selection.

hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号