开发者

Drupal - CCK field - make required

开发者 https://www.devze.com 2023-01-24 10:03 出处:网络
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 use

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 bei开发者_StackOverflow社区ng so messy, I couldn't seem to paster it correctly, it kept getting cut off.


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 ;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消