Posted by RiteshJain on March 5, 2010 at 8:03pm
8 followers
| Project: | Registration Role With Approval |
| Version: | 6.x-1.1 |
| Component: | Code |
| Category: | feature request |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
First of all, this module is truly simple and does the job that 99% developers would require.
Role checkboxes should be marked as required. I dont know why did'nt you made it a required filed. I have changed your source code by adding another property '#required' => TRUE,. You may think to incorporate it in next release.
Thanks for the module..
Ritesh..
Comments
#1
I don't want any of the roles I have on my registration to be required. Maybe this could be an optional feature?
#2
For some reason, when I add the required=true attribute, my checkboxes disappear if I do not select one and click submit. Is this a problem with not knowing exactly where to put the required=true attribute or is there more that needs to be done with the module to enable this.
Another thing I would like to do is change the form to use radio buttons instead of check boxes. I switched the type to 'radio' but that just puts one radio button next to the label and doesn't have the actual options in the form. Any help with this would be appreciated.
Other than this, I'm happy with this module. Thanks very much for writing it.
#3
We might add this as an option in configuration to set roles to required or not.
apt94jesse: To display multiple radio buttons you should use type 'radios'.
#4
'radios' worked perfectly, thanks very much!
#5
Hi, I am after the roles I have created to be required on registration also. After reading your post it seems like you have managed to implement this into the module code. Could you please tell me where you put the required=true attribute (file, line number) as I don't have a clue where to insert it as my knowledge of PHP is zero.
Thanks :)
#6
Managed to sort this out on my own, feeling very chuffed with myself, it does make the module better having the role required on registration, well, it does for me, it may not for others so I guess its good that you can play with the code to suit your needs.
One very happy novice drupaller :) :) :)
#7
I am not able to get the radios to work! I replaced checkboxes with radios in two places but I am getting an error on line 54 on the row with foreach($role_selected as $rid=>$value) { !
I am not a programmer can someone help with changing the checkboxes with radios?
<?php
$roles= array();
function registration_role_with_approval_menu() {
$items['admin/settings/registration_role_with_approval'] = array(
'title' => 'Registration Role With Approval',
'description' => 'Configure Registration Role With Approval.',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function registration_role_with_approval_form_alter(&$form, $form_state, $form_id) {
if ($form_id=='user_register') {
$display_roles = variable_get('registration_role_with_approval_profile_roles', $roles);
if (empty($display_roles)) {
$form['profile_roles'] = array(
'#type' => 'radios',
'#title' =>'You Must Configure the Module First',
'#options' => $roles,
);
}
else {
$approval_roles=variable_get('registration_role_with_approval_profile_roles_approval', $roles);
foreach($display_roles as $role) {
if (0 != $role) {
$role_name = db_result(db_query("SELECT name FROM {role} WHERE rid=%d",$role));
if (in_array($role,$approval_roles)) {
$role_name .= " *needs administration approval";
}
$roles[$role] = $role_name;
}
}
$form['profile_roles'] = array(
'#type' => 'radios',
'#title' =>'Choose a role',
'#options' => $roles,
);
$form['#submit'][] = '_registration_role_with_approval_register_add_role';
}
}
}
function _registration_role_with_approval_register_add_role($form, &$form_state) {
$role_selected=$form_state['values']['profile_roles'];
$uid=$form_state['user']->uid;
$username=$form_state['user']->name;
$approval_roles=variable_get('registration_role_with_approval_profile_roles_approval', $roles);
foreach($role_selected as $rid=>$value) {
if($value!="0") {
db_query('INSERT INTO {users_roles} VALUES (%d, %d)',$uid,$rid);
if(in_array($rid,$approval_roles)) {
//Block account until approved by administrator
db_query("UPDATE {users} SET status=0 WHERE uid = %d", $uid);
$user_approval[]=$rid;
}
}
}
// Send email notification to administrator
if (!empty($user_approval)) {
$params = array(
'username' => $username,
'uid' => $uid,
'user_approval' => $user_approval,
);
$admin=user_load(1);
$email=$admin->mail;
drupal_mail('registration_role_with_approval', 'registration', $email, language_default(), $params);
}
}
function registration_role_with_approval_mail($key, &$message, $params) {
switch ($key) {
case 'registration':
// note: data can be passed to this function in the $params array
$output = "A new user has registered with username: ".$params['username'];
$output .= "\n\nThis user has requested these role(s) that need your approval: ";
$i=0;
foreach($params['user_approval'] as $user_approval) {
$role_name=db_result(db_query("SELECT name FROM {role} WHERE rid=%d",$user_approval));
if ($i==0) {
$output.=$role_name;
}
else {
$output.=", ".$role_name;
}
$i++;
//$output.=$params['approval_roles'];
}
$output .= "\n\nYou may review his account here:\n\n";
$output .= url("user/{$params['uid']}/edit",array('absolute' => TRUE));
$message['subject'] = t('New Roles Request');
$message['body'] = t($output);
break;
}
}
//* The settings form used by Registration Role With Approval.
function _registration_role_with_approval_admin_settings_form() {
//Obtain all roles
$result=db_query("SELECT * FROM {role} WHERE rid>2");
if ($result == TRUE) {
while($role=db_fetch_array($result)) {
$roles[$role['rid']]=$role['name'];
$default_value[$role['rid']]=0;
}
$form['registration_role_with_approval_profile_roles'] = array(
'#type' => 'checkboxes',
'#title' =>'Roles',
'#options' => $roles,
'#description' => "Choose roles that will be displayed on registration form",
'#default_value' => variable_get('registration_role_with_approval_profile_roles', $default_value),
);
$form['registration_role_with_approval_profile_roles_approval'] = array(
'#type' => 'checkboxes',
'#title' =>'Approval Roles',
'#options' => $roles,
'#description' => "Choose roles that needs administration approval. Users that select this role during registration will
be disabled until administrator approves them.",
'#default_value' => variable_get('registration_role_with_approval_profile_roles_approval', $default_value),
);
return system_settings_form($form);
}
}
#8
Here the code for working with radio buttons ;)
YEAH FUCKING YEAAAH
#9
Hey guys,
don't forget about other modules that auto-assign roles, like "auto_assign_role". Don't make role selection required on the user registration form, as that conflicts with other settings.
#10
See #936074: Hide the 'Choose a role' field if no role is selected for display on the registration form and http://drupal.org/node/697816#comment-3548786 as to why this setting should NOT be set to required, but rather adjusted a little for smoother performance.