0

On an e-commerce site I've got two roles, wholesaler and retailer: I'm using Auto-assign Role to manage the registrations, with two different registration pages.

  • Retailers register at mysite.com/user/register;
  • Wholesalers register at mysite.com/user/wholesale

I'm also using Ubercart and Ubercart Addresses and I need the applicants to the wholesaler role to enter mandatorily the Company name: how can I set it?

CCK is not a solution, neither are other modules, because all I need is that field to be mandatory.

4

2 回答 2

1

这是 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;
  }
}

我还没有测试过上面的,所以它可能需要调整。

于 2010-11-28T21:29:44.097 回答
0
<?php 

function dag729_form_alter(&$form, &$form_state, $form_id ) {
    if ($form_id == 'user_register' && $_GET['q']=='user/wholesale') {   
    $form[0]['company']['#required'] = TRUE;
  }
}

而已。

实际上无法满足 UID 要求,因为在注册过程中用户是匿名的。

于 2010-12-09T15:49:52.557 回答