Customizing Drupal user account form - php

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>Register as A or Register as B</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.

Related

Wordpress ask user's their desired role as a dropdown menu while registration

I want to add a custom field to the Wordpress registration form without using any plugins. I want to add a dropdown menu with user-roles ( some roles I have created). Once the registration is complete the user should not have the ability to change their roles ( only admin can do that, selecting role as admin should not be allowed).
Any help will be appreciated.
I understand that you do not intend to use plugins, but you nevertheless use a theme, be it implemented by your team or some widely available theme. In any case, that theme has an implementation for your registration, so:
Find the registration form
Make sure that you find out where the registration form is.
Add a field to the form
Be it in a CMS editor or in a PHP/HTML file you must be able to edit it and add a field
Find the code which runs when a registration is posted
Again, you need to seek and find.
Enhance your functionalities which save fields
You will need to track and save the posted value
Change the database schema
You will need to do some changes on the MySQL schema in order to support the new field on database-level.

How to implement admin interface for drupal7 custom module?

I am new to Drupal.I am working on creating custom module in drupal7.
I created one review form(contains name,rating,comments fields) in front page.
After user submit this form I stored data in database.I retrived and displayed this data in block.This is what I have done.
But I need admin interface for this module As "the user submitted rating displayed in admin section" and "admin need to perform approve,edit,delete operations on user rating".
How to implement this.
Please help me any one. Thanks in advance.
Did you search google? If so, it probably would have directed you to Creating a module configuration (settings) page
If i haven't misunderstood your question I think the proper way to achieve this is by adding your module permissions into the drupal permissions system.
You can achieve this by adding to your module the hook_permission
function custommodulename_permission() {
return array(
'custommodulename' => array(
'title' => t('custommodulename'),
'description' => t('Access URL for custommodulename module.'),
),
);
Then you can add the admin permission into admin/people/permissions page.
Not sure how are you storing the data you collect with your form but my advice is to create content type with fields your form collects. Then, when your form is submitted for storing that data you just have to create new node in your content type. You'll easy find some tutorial explaining how to create new node of some content type programmatically. That way you'll have your submitted data "in the system" so you can user i.e. views module to retrieve you data.

Drupal 7 user module customize for registration for different roles

I have a requirement of customizing user signup form in Drupal 7. i am not getting any relevant help from the internet . so i thought i should ask the expert here.
Requirement is i have two roles say "Student" and "Teacher". I have to use default user module for their signup by setting their roles automatically.
Now there will be two links one for Student signup another for Teacher Sign up. When user click on Student SignUp i am hiding some fields of default user module which are suppose to fill by a teacher, so student will see only fields, which are specified. Same for Teacher i am hiding fields which student suppose to fill.
So basically with the use of default user module i have to perform the sign up process.
Solution what i think could be possible :
I can set a variable in the link saying "studetnSignUp?status=student" and same for Teacher "studetnSignUp?status=teacher". Now the problem is i can do this in php but do not have proficient way to the same in drupal.
If it can be possible with any other approach please let me know. As it is really urgent for me. Your support will be really appreciated.
Thanks.
You can look into Profile2 in combination with Profile2 Registration Paths. It provides you with the ability to set a unique registration path for each Profile2 profile type. Per profile type you can define different fields. And I think a helpful feature is that it can assign user roles by registration path.
I would grab the passed parameter using menu and then call
hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_profile_form') {
// do your processing here
}
}
alter the layout of the form dependant of the user, and specify the users role in the form to, ie teacher or student

How to make an administration page in Drupal? Is it even possible?

Let's say I'm making a blog in Drupal 7, and I want my end user to see a link: "Add Post", and when he clicks on that link he can add a new content. But instead of the default administration page, is it possible to create a new one, which has just the post title, tags, message and etc?
I've been searching for 2 days now, founding nothing about where to start/how to start a specific administration page instead of the default one.
You will have to create a specific module for that which will:
define the blog post editing form you want to have
define a page through a hook_menu function that includes the form
define a menu entry for it in the administrative menu
etc.
You should really get a little more into extending drupal by reading some pro drupal 7 book.
At least start reading http://drupal.org/node/1074360
Another very good starting point is the drupal "examples" module, which provides example code for most things your modules need to do:
http://drupal.org/project/examples
You could probably do all you need to by adding a template for the blog posting page to your theme. This lets you customise the display of the form, without needing to get too deep into Drupal programming.
Alternatively, you could create a module to replace the default blog submission form with one if your own design.
The theming and module design guides on the Drupal website give lits if detail on both these approaches.
James
you can have a different theme for management section, you can have multiple permissions depending on role, you can customize any page using ***node.tpl
Every add/content_type is a form. Forms can be altered with hook_form_alter or hook_form_id_alter.
If you want to have different fields that are shown for different roles, first see if it could be done on the admin/people/permissions page, if not write extra if conditions inside the form_alter.
e.g. check user role:
global $user;
// Check to see if $user doesn't have the administrator role.
if (!in_array('administrator', array_values($user->roles))) {
// Alter the form
}
You can check the form variables with dpm($form) when the Devel modules is enabled.

Drupal 6: custom profile fields and saving data to a DB

So i've added several some custom profile fields (administer -> profiles) which is all fine but completely useless if I can't store the information in a database. I've been searching for hours now trying to figure out the "best practices" way for doing this with very little luck.
Do I add the new columns to the Users table? Do I create a whole new table? I even found a vague reference that the core profile module should have added those columns for me anyway? And that you should be able to use CCK in the core profile module (but I don't have any options for that)?
And then I would obviously want to allow user to update their own fields but the the custom profile fields aren't included in the $form array...
PS arrrggg! Drupal is driving me around the bend with its inconsistencies and having to hack it all the time!
If you use the core profile module, the database storage is provided automatically and you will not need to modify anything in the database. On install, the module adds two tables to the database, profile_fields to store your custom field definitions and profile_values to store the user supplied data for those fields.
The fields are automatically added to the user edit forms, via the hook_user implementation in profile_user() - the same mechanism is used to add the values of those fields to the user object when that gets loaded.
So if those fields don't show up for you, something is fishy - have you added your fields with 'categories'? If so, they won't show on the standard user edit page, but on additional new pages (one per category). These are added as menu type MENU_LOCAL_TASK, so they should create new 'tab' entries at the top of the user edit page - maybe you have a theme that does not display the tabs?
Another thing to check would be the fields visibility settings chosen on the fields configuration form. If that is set to 'hidden', the field is only accessible for administrators and module/theme code. You should at least set it to 'private' if the user is supposed to edit it himself.
As for using CCK fields, I don't think that this is possible with the core profile module (maybe some extension module provides this). A different approach is taken by the Content Profile Module. It creates a custom node type for user profiles so that the profile values are stored as standard Drupal nodes. One advantage of this is that you can use all CCK fields for profiles, as you just need to add those to the created node type.

Categories