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.
Comments
Comment #1
fgmComment #2
Zen commentedCSS IDs should use hyphenation rather than underscores.
Thanks
-K
Comment #3
fgmThis 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.
Comment #4
fgmComment #5
dries commentedWhat does the original code generate? (Why do we need these hidden form id's?)
Comment #6
Zen commentedHi :)
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
Comment #7
Steven commentedNeeds to be merged with:
http://drupal.org/node/62366