5

In context of this question I wanted to ask - how to provide custom controls to use with Form API? Especially ones that needs to be exploded into javascript and at least one additional hidden field to make their GUI work.

I can find manuals for Drupal 6 easily enough, but somehow I can't spot ones for 7. I know I need to start with hook_element_info(), but hook's description for Drupal 7 points to a manual for Drupal 6.

Could anyone provide step-by-step instruction how to make it work?

2 Answers 2

3

Searching Google for "hook_element_info tutorial" brings up Create custom Form API elements with hook_element_info() in Drupal 7.

There is also the Examples for Developers project, which is included in the documentation at http://api.drupal.org. The Form API Example module implements hook_element_info() and contains a number of example elements in the form_example_elements.inc file.

5
  • Examples for Developers are great, if someone already roughly know the direction. Manual seems good, thank you. Don't know why I haven't seen it in my Google results. It was more consistent in the old times, when order of googled pages depended solely on those pages and keywords entered, not on user, his position on earth etc.
    – Mołot
    Commented May 28, 2013 at 8:18
  • Yes, the examples can be overwhelming at first, because they provide all information at once instead of taking you through the process step-by-step. Regarding Google search: I didn't mean to imply you hadn't searched. Next time I'll type "For me, searching Google brings up example.com." Commented May 28, 2013 at 9:16
  • I didn't feel offended. It's just a bit irritating when two people looking at the same page, performing the same search, gets different results. Especially that I probably taught it to serve me wrong results, 'cause I clicked pointless ones in the first place, before I started to include hook name in my search. and it's hard to make it forget that. Bad UX for me.
    – Mołot
    Commented May 28, 2013 at 9:26
  • 2
    I agree. Google is pretty smart but it can get annoying. Maybe we should use incognito windows more often. Commented May 28, 2013 at 9:57
  • Here's another great tutorial on creating form elements - phase2technology.com/blog/…, and another one - silviogutierrez.com/blog/custom-drupal-elements-forms
    – hargobind
    Commented May 23, 2015 at 8:35
2

Look at Examples project. Especially check form_example module. I think this is the best source of knowledge about practical use Form API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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