3

I'm building a costum form using Drupal (7) Form API

I want to create a text field with possibility to add multiple values through autocomplete. The idea is to allow the user to add taxonomy terms to my instance that is to be saved through the form.

Final goal is to present selected values in a table with fields

Term name | Vocabulary | Actions

Where Term name is a input field with autocomplete. When a term is selected, Vocabulary name is appended through JS, and actions just contains a "Remove" button.

And finally under this table I'll have a button with "Add another value". I'm seeing this done through the Fields API, if I'm setting a field to allow unlimited values. But I want to build this my self, as I'm not using a field, but my own costum database.

How do I accomplish this through Form API?

4

Found the solution in AHAH

With AHAH you can dynamically add new fields to the form using JavaScript. Be sure to read http://drupal.org/node/331941 with examples of implementations from e.g. the Poll module.

  • 1
    And a tip is to take a look at the Examples module drupal.org/project/examples which has good examples of the #ajax usage in form fields. – mtrolle May 15 '12 at 9:32
  • Good starting point is to see how multiple choices are implements in Poll module. – Eugene Fidelin Sep 7 '12 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.