Hello,
If someone wants to use multiple webforms on one page using panels or some similar idea, is there a way to change the CSS ID of one of those webforms so that it validates correctly? Or should I code a basic webform myself, without using a second Webform.
Thanks,
Tiuya
Comments
Comment #1
quicksketchAs far as I know, Drupal core should auto-increment elements that use the same ID, preventing them from conflicting (or having any useful purpose for CSS styling).
Though just looking at it now, it seems that Webform doesn't run through this function for it's assigned IDs (see http://api.lullabot.com/form_clean_id). So to fix this, we should probably run all of the component wrappers through this function to ensure they are unique.
i.e.
Should be:
Though I'm not sure this would fix all the duplicate IDs. What's the general markup that seems to be causing duplicates for you? There's a similar issue at #666390: Webform does not W3C conform (duplicate IDs for elements with the same form key).
Comment #2
Tiuya commentedHere are the validation errors:
Now, looking at this again, I think I could name those two something else and fix the problems. I don't know what happened, but last time I could have sworn that it said the webform ID itself was a duplicate. I'll write back to report whether the fix worked or not later.
Comment #3
jludwig commentedYou can fix that by changing the 'Field Key' to something else under 'Advanced Settings' on the webform component page. That is where the webform component ID comes from.
Comment #4
Tiuya commentedFixed! Thanks
Comment #5
bartezz commentedHi quick,
Sorry to open an old issue but I think I'm running into what you mentioned in #1.
My form IDs are unique but not the component IDs.
In webform_hooks.php I've changed this;
Flushed caches and such but it doesn't seem to have any effect?
I'm adding the webform to a node via template.php like so;
For debugging purposes I emptied the complete webform_hooks.php file but got no errors. Is this even used still?
Might be tired and overlooking things...
Cheers
Comment #6
quicksketchThis issue has largely been fixed already by #666390: Webform does not W3C conform (duplicate IDs for elements with the same form key).
That file is never used, it's used for documentation.
What are you needing that's not done?
Comment #7
bartezz commentedHi quick,
Well I am including a webform into nodes of a certain type. Therefore in a view of these nodes a single webform is loaded multiple times on a page. The single webform has a unique ID everytime it's included into the node but the components all have the same IDs causing trouble with compliancy and jQuery functionality.
Hope I have explained well...
Cheers
Comment #8
goldhat commentedFacing this issue myself on a page where I have the same form output twice. All the ID's used in the form get incremented ("--2") except for the email field wrapping div within the form.
I've tried every option I could think of to try to randomize that ID using hook_form_alter with a PHP rand affixed to the ID. Nothing has worked for me so far.
Why oh why does Webform need to give its wrapping divs an ID anyway??
Below is the form output. My problem is the id "webform-component-sparkmail-email-field" added to the div that wraps around the input field.
Comment #9
quicksketchIf you want to remove the ID, you can do so by overriding theme_webform_element().
Comment #10
carlhinton commentedHave you seen the module webform-classes http://drupal.org/project/webform-classes
Comment #11
madhavvyas commentedI have very similar kind of issue #8
In my project we were showing webform in panel through page manager. Webform id is suffixed with --2
and due to that I am facing issue in some other webform based modules such as webform_conditional .
Here is the form tag id which is suffixed by --2
<form id="webform-client-form-2246--2" class="webform-client-form"Can you submit patch for the same.
Comment #12
quicksketchHi guys. The remaining issues described on this page (from #7 onwards) are simply functionality that MUST be intact in order to pass W3C validation. If you display the form multiple times per page, each copy needs different IDs. If you want to target an element multiple times per page, use a class on that element instead. For 3.x you can use the webform_classes module mentioned above. Webform 4.x includes this functionality built-in.