I am writing support for g2image (similar to img_assist but for Gallery2) into a module (the details of g2image itself are not that important -- except that it's not my code). It needs to be passed a couple of parameters including the id of the form and the id of the textarea (I can get this).

How can I get the id of the form that the textarea is in?

I could use hook_elements with 'form' I suppose to find the form id, but then how can I associate it with the correct textarea?

Thanks for your help.