I want to add form elements inside my custom form when some body clicks on the link outside the form. Links are like :

  • Add textfield
  • Add selectlist

When user click on any link it via ajax add an element to the form. I just want and idea whether it is possible or not in drupal. If it is possible then just give me some idea about this.



This is absolutely possible. I would highly recommend that you check out Drupals AJAX framework and Form API.

You might even be able to use the Form API's "#states' features to accomplish what you're looking to do without having to make any AJAX callbacks.

There is also the Examples for Developers project that I believe contains code that accomplishes what your hoping to accomplish.

You can view a live version of the Examples for Developers project here. You can find the the AJAX Examples in the navigation on the left. Here are a few of the specific sections you should look at:

These should help you get started with the AJAX framework in Drupal.


You should take a look at Examples module or in particular the AJAX example https://api.drupal.org/api/examples/ajax_example!ajax_example.module/7 It's really helpful.

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.