Drupal 7 user module customize for registration for different roles - php

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

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.

User registration on Joomla

User registration:
One user registration and there are two types:
1) Teacher
2) Student
when user come in user registration form and put mandatory information, And also there drop down list Teacher and Student, Choose one option.
And open their related fields when choosing second option first option is hidden and second will appear on the screen.
And then register.
Try using two different templates for registration. One is for Teacher and one is for student. And override the registration on your templates. That is simple and you'll have full control over the two different sections.

drupal 7 show/hide field for a role

is there a module to show/hide fields to a specific role in Drupal 7?
I know Field Permissions Module, but it is not exactly what I need.
I have two fields:
picture
picture_premium
and these roles:
anonymous
authenticated
premium
the picture field should be visible for: anonymous and authenticated
the picture_premium field shoudl be visible for: premium
note that premium should not see the picture field.
You should use Field Permissions module.
It's built just for that.
Hope that helps... Muhammad.
To expand on that a bit - in the scenario as described, Field Permissions would not work, as all premium users would also be authenticated. The only way you could use Field Permissions to do this is by assigning a separate role like "regular" to all non-premium authenticated users. Then you could make the picture field visible to anonymous and regular, and picture_premium to premium.
I don't know yet if there is a better solution.

Joomla additional User Data

Im trying to create some new extensions in joomla.
I want to add additional information for each user. I know I could achieve this by creating my own custom user profile plugin and adding additional fields, but this will then add those fields to the users profile page.
I want to show the new fields separately. For example i may have one link on the users page which takes them to there basic information e.g. name, email etc. And another link which shows them the 'additional' fields.
The additional fields will not be personal information, that's why I want to display them separately.
My question is, how do I achieve this? Can I simply add additional fields to each user or will I have to write a completely new component?
UPDATE: I cannot use an existing extension as I want full control over the code. Also, the additional information will NOT be added by the user, it will only be added by admin.
You do not have to display profile fields on the user profile page with the standard user profile You can configure it only to display to the administrator. You simply make different settings for the different forms (there are 4 throughout the cms). Follow the pattern in the core plugin.
In the end I decided it was better to create my own component. Mainly because hacking joomla would be a pest when updates came out and JED did not provide the specific extension that I wanted.
There are probably 2 main way of doing this.
You can create an extension where user fill in the information and it stores the data in separate database table which connects to the #__users table.
You could download an extension from JED for extended profiles. There are non-commercial and commercial extensions so take a look here to see if there is anything that might suit your needs.
Personally I would install a pre-made extension and it will save a lot of work/trial and error.
check this out: http://extensions.joomla.org/extensions/clients-a-communities/user-management
If you have added or changed any coding like adding fields to user table or customize registration page in joomla it will restore to default once you upgrade your Joomla version.
The way to do this is:
You have to create another table which contains the other extra information and should with userid from #__users.
When submitting the form you have get the another table by using this Joomla code.
$module_table = JTable::getInstance('modules', 'profileTable');
Modules -> means table name which you created.
ProfileTable -> means "component name" is Model name and "Table" is common.
Then you have to pass the post values to this table like this..
if (!$module_table->bind($post))
{
return 0;
}
if (!$module_table->check())
{
return 0;
}
if (!$module_table->store())
{
return 0;
}
This way, you can store additional data for users. For displaying purposes, you will need to join the two tables by using userid and display it...
All the best..

Customizing Drupal user account form

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.

Categories