I'm doing a bunch of work porting the Protoype ajax system to work on Drupal. Many of the functions will need to target the "form" element.

Maybe I'm missing something, but it looks like the form_id in drupal_get_form('form_id', &$form, $callback) doesn't actually make it into the form tag. Instead it ends up in <input type="hidden" name="edit[form_id]" value="form_id" />, but doesn't actually define an id of anything on the page.

Shouldn't this form_id be the id of the form element?

-Jeff

CommentFileSizeAuthor
#3 form_id_1.patch1.09 KBchx
#2 form_id_0.patch10.74 KBchx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

this is still happenning . i agree that this is not intended behavior. anyone from form api team able to comment?

chx’s picture

Status: Active » Needs review
FileSize
10.74 KB

This is our (== Adrian & I) intended behaviour, but I can see how people would expect what jjeff describes, so here is a patch.

chx’s picture

FileSize
1.09 KB
Dries’s picture

Can't we write:

    $form['#id'] = $form_id;

instead of:

  if (!isset($form['#id'])) {
    $form['#id'] = $form_id;
  }

Why do we need two ways to set the idea?

chx’s picture

Once again the naming causes confusion. Too many good words are already used by HTML, and while we have renamed post_process to after_build I do not see right what would be a good for a parameter which identifies the form for Drupal. It is not a DOM identifier for HTML, no. It is possible for whatever reason that $form['#id'] , the DOM identifier differs from $form_id which is the Drupal form identifier.

jjeff’s picture

I would have written it the way you did, CHX.. But upon further thinking about Dries' response, isn't it the same module that defines $form['form_id'] as defines $form['#attributes'] = array('id' => 'form_id');?

In other words isn't the purpose of both of these basically the same: to give the form an identifier? And isn't this definition made in one place: the module?

So I think it's probably safe to assume that

    $form['#id'] = $form_id;

...of course as a developer, I would probably be very confused if/when my $form['#attributes'] = array('id' => 'form_id'); got reset and didn't make it to the page...

So I could certainly go either way on this one and it's definitely safer to go with CHX's method, but Dries has a good point.

-Jeff

chx’s picture

Not so. Let's state this again: $form['form_id'] is a critical element of the form API's inner working, because that'll let it know which form has been submitted. Therefore we overwrite this element without mercy. Form API , on the other hand does not depend on $form['#id'] and it being the ever-extendable one, I do not see why we should not let ppl set their own #id if they want.

jjeff’s picture

Okay CHX, you've won me over. :-)

+1 CHX

-jeff

Crell’s picture

Status: Needs review » Reviewed & tested by the community

I can't think of a reason why someone would want $form['#id'] != $form['form_id'], but I can't see where permitting it causes any immediate problems, either. So +1 to the patch in #3 from me as well.

adrian’s picture

+1 on the form_id.
It's very useful information for themers.

Steven’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)