1

Is it possible and how to implement one textfield with multiple values in drupal form?

Say, I have the next code:

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

What should I change for this form

  1. to show multiple textfields, e.g.

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

  2. to call variable_set('mymodule_email_recepient', array( /*some values*/ )) on submit.

Thanks for advance!

Community
  • 1
  • 1
artyom.stv
  • 2,097
  • 1
  • 24
  • 42

1 Answers1

1

I was searching something similar today and the solution I used may be good enough for you too.

Using CCK module I created a content type destined only to shelter fields that should be used in my custom module.

Than I created a cck field (in my case a nodereferente auto-create field) inside that content type.

Finally, i inserted the existing CCK field into my custom form using the following tip: http://coder1.com/articles/adding-cck-field-to-custom-form

Hope it helps.

ndvo
  • 939
  • 11
  • 16