2

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.

googletorp
  • 33,075
  • 15
  • 67
  • 82
Ankh2054
  • 1,103
  • 2
  • 16
  • 39

1 Answers1

3

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 ;
  }
}
googletorp
  • 33,075
  • 15
  • 67
  • 82
  • thanks for the help. That code above was an example, and what I really want to make a required field is "Group registration key", but I am unsure of what the its field name is. Any ideas as to how I could find this out ? – Ankh2054 Nov 11 '10 at 22:36
  • @Ankh You can use the devel module and do `dpm($form)` to be able to inspect the form value and figure out what you need to alter. – googletorp Nov 12 '10 at 09:18
  • thanks, ive added dpm($form) to the template.php, expecting it to provide values when im at the edit or create new content type. Im a little cluless when it comes to php, so could yuo perhaps be so kind and point me in the rigth direction. thanks again :) – Ankh2054 Nov 14 '10 at 17:35
  • I ended up editing the organic group key module itself and adding the field required = true , which did the trick. thanks for you help – Ankh2054 Nov 15 '10 at 12:07