这是 Lullabot 的教程,解释了两种方法:http ://www.lullabot.com/articles/modifying-forms-drupal-5-and-6
在模块方法中,您需要设置如下内容:
$form['company-field-name']['#required'] = TRUE;
我不知道相关字段的实际名称(我将公司字段名称放在哪里),因此您必须通过将 $form 打印到屏幕或文件并阅读输出来研究它。
有关创建模块的其他信息:
我将假设您正在对 Drupal 6 进行模块覆盖,该模块在我上面发布的链接中的“模块 hook_form_alter(): D6”标题下列出。
这些信息可以在 Drupal 的网站上找到,这里:http ://drupal.org/node/231276
您需要做的是在您网站的 settings.php 文件所在的位置创建一个模块目录(可能在站点/默认值中)。在 modules 目录中,创建另一个目录,该目录是您的模块的名称。我通常将模块命名为 zzzmods 或类似名称。在该目录中,创建一个同名的信息文件(即:zzzmods.info)。在该文件中,添加以下三个具有相关值的键:
name = "Module name"
description = "Module description."
core = 6.x
现在,在该目录中创建一个同名的模块文件,即:zzzmods.module。在该文件中,您可以放置相关代码,如下所示:
function zzzmods_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
// You need to figure out what the id is of the form and put it here.
// You can use the Form Inspect module to help with this and the field name below.
case 'relevant_form_id_here':
global $user;
// Specify the role you're looking for here.
if (in_array('Wholesalers', $user->roles)) {
$form['relevant-field-name-here']['#required'] = TRUE;
}
break;
}
}
我还没有测试过上面的,所以它可能需要调整。