[development] finding the $form_id of a particular form /
	allforms.
    Nedjo Rogers 
    nedjo at islandnet.com
       
    Sun Jul  2 16:09:52 UTC 2006
    
    
  
> Heh, I hit this just yesterday. While my solution probably wasn't 
> "correct",
> it worked for me. I just put a "print ($form_id);" as the first statement 
> of
> my custom form_alter function, then I navigated to the form I wanted the 
> ID
> for, and it was the first thing printed at the top of the page.
Somewhat related: In the jstools module we cache references to each form, 
along with a page they're available on. The resulting array can be used to 
generate a list of available forms for, e.g, attaching a behaviour to given 
forms, as we do in formcheck.module. It can also be used, with some Forms 
API tricks, to fetch a particular form's array. Here's the caching function:
/**
 * Implementation of hook_form_alter().
 *
 * Register available forms into an array variable.
 */
function jstools_form_alter($form_id, &$form) {
  // If this form_id is not already registered, register it.
  $options = variable_get('jstools_forms_options', array());
  if (!array_key_exists($form_id, $options)) {
    $options[$form_id] = $_GET['q'];
    variable_set('jstools_forms_options', $options);
  }
} 
    
    
More information about the development
mailing list