finding the $form_id of a particular form / all forms.
Hello, hook_form_alter() allows us to change forms according to their form_id: http://api.drupal.org/api/HEAD/function/hook_form_alter Am I missing something easy, or the only way to figure out what is the form_id of a specific form is to pour over the code and figure out which module initialized the said form? Devel.module doesn't seem to help with that. thanks, Augustin. -- http://www.wechange.org/ Because we and the world need to change. http://www.reuniting.info/ Intimate Relationships, peace and harmony in the couple.
On 7/1/06, Augustin (a.k.a. Beginner) <drupal.beginner@wechange.org> wrote:
hook_form_alter() allows us to change forms according to their form_id: http://api.drupal.org/api/HEAD/function/hook_form_alter
Am I missing something easy, or the only way to figure out what is the form_id of a specific form is to pour over the code and figure out which module initialized the said form?
Or look into the HTML output. Each HTML form-element has an ID attribute. Devel.module doesn't seem to help with that. It could I suppose. Eg by implementing a hook_form_alter() that stores all the ids Drupal requested to alter and then display that list at the bottom of the page. Or maybe use hook_form_alter() to add a visible form-item (which mentions the form_id) somewhere in the form. But you're right, at the moment, devel.module has no such feature. Use the source Luke :-) Robrecht
On Sat, 01 Jul 2006 12:05:39 +0200, Augustin (a.k.a. Beginner) <drupal.beginner@wechange.org> wrote:
Hello,
hook_form_alter() allows us to change forms according to their form_id: http://api.drupal.org/api/HEAD/function/hook_form_alter
Am I missing something easy, or the only way to figure out what is the form_id of a specific form is to pour over the code and figure out which module initialized the said form? Devel.module doesn't seem to help with that.
thanks,
Augustin.
Make a module (here test.module): <?php function test_form_alter($form_id, &$form) { $form['test_form_id_display'] = array('#weight' => -20, '#type' => 'markup', '#value' => check_plain($form_id)); } Voila. Regards, Heine // yes, I may be paranoid.
On Saturday 01 July 2006 03:05, Augustin (a.k.a. Beginner) wrote:
Hello,
hook_form_alter() allows us to change forms according to their form_id: http://api.drupal.org/api/HEAD/function/hook_form_alter
Am I missing something easy, or the only way to figure out what is the form_id of a specific form is to pour over the code and figure out which module initialized the said form? Devel.module doesn't seem to help with that.
thanks,
Augustin.
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. -- Jason Flatt http://www.oadae.net/ Father of Six: http://www.flattfamily.com/ (Joseph, 13; Cramer, 11; Travis, 9; Angela; Harry, 5; and William, 12:04 am, 12-29-2005) Linux User: http://www.sourcemage.org/ Drupal Fanatic: http://drupal.org/
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); } }
On Saturday 01 July 2006 06:05 pm, Augustin (a.k.a. Beginner) wrote:
hook_form_alter() allows us to change forms according to their form_id: http://api.drupal.org/api/HEAD/function/hook_form_alter
Am I missing something easy,
Apparently, I was missing many easy ways :) Thank you all for your suggestions in this thread. Blessings, Augustin. -- http://www.wechange.org/ Because we and the world need to change. http://www.reuniting.info/ Intimate Relationships, peace and harmony in the couple.
participants (5)
-
Augustin (a.k.a. Beginner) -
Heine Deelstra -
Jason Flatt -
Nedjo Rogers -
Robrecht Jacques