Inserting more than one form appears to cause ID duplication, which is invalid (X)HTML.

This *seems* be be caused by this line in form.inc/drupal_get_form:

  if (isset($form_id)) {
    $form['form_id'] = array('#type' => 'hidden', '#value' => $form_id);
  }

which apparently generates the non-unique name/id for the hidden element on the form. I've made a tiny patch which seems to work for me, but I'm not sure it doesn't break something else. It does this:

  if (isset($form_id)) {
    $form['form_id'] = array('#type' => 'hidden', '#value' => $form_id, '#id' => "edit-$form_id");
  }

which causes unique name/id pairs to be generated for unique form ids.

CommentFileSizeAuthor
#3 form.inc_21.patch631 bytesfgm
form.inc_20.patch608 bytesfgm

Comments

fgm’s picture

Status: Active » Needs review
Zen’s picture

Status: Needs review » Needs work

CSS IDs should use hyphenation rather than underscores.

Thanks
-K

fgm’s picture

StatusFileSize
new631 bytes

This is no longer an issue in CSS2.1. See http://www.w3.org/TR/CSS21/syndata.html#q4 paragraph 4.1.3.

But it doesn't hurt to have the underscore filtered. Patch rerolled with underscore replacement.

Note that there are lots of them in IDs elsewhere already anyway.

fgm’s picture

Status: Needs work » Needs review
dries’s picture

What does the original code generate? (Why do we need these hidden form id's?)

Zen’s picture

Hi :)

There are three issues here:

a) Hiddens need an ID for Javascript.
b) Presently, having multiple forms on a page means that each form has a duplicate ID of name 'edit-form-id' which is not valid XHTML.
c) Right now, form_clean_id() (which is used by fapi to sanitise ID attributes) allows underscores to be present in them. So, if I have a textfield called $form['user_name'], the ID for that element in HTML would be edit-user_name rather than edit-user-name.

To fix b), a patch was committed in late December that removed ids from *all* hidden elements. To fix a), a patch was committed in late April that gave all hidden elements IDs...

c) is technically a separate issue but is related here by the fact that the '$form_id' in fgm's patch needs to be run through form_clean_id().

Thanks,
-K

Steven’s picture

Status: Needs review » Closed (duplicate)

Needs to be merged with:
http://drupal.org/node/62366