2
votes

I've installed the following module - http://drupal.org/project/og_reg_keys This module adds an additional field to your Organic Group Node types, to allow auser to specify a registration key for users to use to join the group.

The problem is that field is not required to be entered by the user.How can one make this field a required field ?

I found the below code, which makes the CCK field mandatory for users of a specific role, but being a non PHP person I have no idea how to change this to:

  1. Make the Group registration key a required field (not sure what the $form element would be called or where to find this)
  2. To remove the section on the code where it applies to users of a specific role, so that it always applies.

Code:

function mymodule_form_alter(&$form, $form_state, $form_id) {  
switch ($form_id) {  
case 'profile_node_form':  
global $user;  
if(in_array('targetrole', $user->roles)) {  
$form['field_profile_pic'][0]['#required'] = 'TRUE';  
$form['#field_info']['field_profile_pic']['required'] = '1'; 
break  

Any help would be greatly appreciated. Sorry for the code being so messy, I couldn't seem to paster it correctly, it kept getting cut off.

1
Please tag your question with the version of Drupal you are using. ex: drupal-6Greg

1 Answers

3
votes

This should make it required for all users:

function mymodule_form_alter(&$form, $form_state, $form_id) {  
  switch ($form_id) {  
    case 'profile_node_form':  
      $form['field_profile_pic'][0]['#required'] = 'TRUE';  
      $form['#field_info']['field_profile_pic']['required'] = '1'; 
      break ;
  }
}