1

是否有可能以及如何以 drupal 形式实现一个具有多个值的文本字段?

说,我有下一个代码:

function mymodule_admin_settings() {
  $form['email'] = array(
    '#type' => 'fieldset',
    // ...
  );
  $form['email']['mymodule_email_recepient'] = array(
    '#type' => 'textfield',
    '#title' => t('Recepient'),
    '#default_value' => variable_get('mymodule_email_recepient', 'email@domain.com'),
    '#element_validate' => array('mymodule_email_validation'),
    '#maxlength' => 30,
    '#required' => TRUE,
  );
  // ...
  return system_settings_form($form);
}

我应该为此表格更改什么

  1. 显示多个文本字段,例如

    <input name="mymodule_email_recepient[]" type="text" />;

  2. 调用variable_set('mymodule_email_recepient', array( /*some values*/ ))提交。

感谢提前!

4

1 回答 1

1

我今天正在搜索类似的东西,我使用的解决方案可能对你也足够好。

使用 CCK 模块,我创建了一个内容类型,仅用于存放应在我的自定义模块中使用的字段。

比我在该内容类型中创建了一个 cck 字段(在我的情况下是一个 nodereferente 自动创建字段)。

最后,我使用以下提示将现有的 CCK 字段插入到我的自定义表单中:http: //coder1.com/articles/adding-cck-field-to-custom-form

希望能帮助到你。

于 2011-10-11T17:50:38.663 回答