When I have a page containing multiple forms - search, simplenews email signup block, and a webform block - the id for the webform block submit button isn't getting a unique ID and is thereby failing W3C validation. I read that the IDs are automatically assigned via FAPI, but in this case it isn't working. Any idea how to fix?

Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

budda’s picture

Project: Webform Block » Webform
Version: 6.x-1.1 » 6.x-3.x-dev

Hmm, this is probably something that needs addressing at the webform.module layer, as the block module i simply embedding the output generated by webform module.

cap60552’s picture

I too am experiencing this problem. I have a site where I have the webform in a block, and also have the site search block enabled. Both forms contain the "edit-submit" ID and thus fail the W3C Validation.

cap60552’s picture

FileSize
765 bytes
777 bytes

I have created a patch for version 2.9 and the 6.x-3.0 dev version (as of today) to fix this issue on the webform submit button and attached them to this response.

Other modules not specifying an ID for their submit button would also need to be patched in a similar matter, but this will correct the problem in webform.

quicksketch’s picture

Priority: Normal » Minor

The suggested changes still won't fix the problem if you've got two Webforms on the same page (one in a block and one in the middle of the page, or two as blocks). Technically this is a Drupal core bug, I'm not sure Webform should be compensating for it.

Bartezz’s picture

Is there an issue queue for the core bug, can't find it?!

Cheers

trothwell’s picture

I've come across the same issue as well, any fixes available?

trothwell’s picture

FileSize
490 bytes

Hey quicksketch, I've been looking into this and found that it is related to webform setting the id specifically as "edit-actions".

webform.module line: 1718

Attached a simple patch that probably wouldn't be the most appropriate solution. Please point out any downsides of doing this...

Cheers.

Just realized I'm referring to edit-actions not edit-submit, I think it's a similar issue anyway. May need to create a new ticket.

Bartezz’s picture

Hi Tom,

I needed a solution to this as well as I was getting validation errors. But I kept getting validation errors due to the fact I added the exact same webform as a block multiple times on a page;

<div id="edit-actions-3" class="form-actions form-wrapper">
<!-- clipped html -->
<div id="edit-actions-3" class="form-actions form-wrapper">

I created a new patch preventing this by using the form_clean_id() function.

<div id="edit-actions-3" class="form-actions form-wrapper">
<!-- clipped html -->
<div id="edit-actions-3-1" class="form-actions form-wrapper">

Any chance you will commit this patch Quicksketch?

Cheers

quicksketch’s picture

Status: Active » Needs work

That looks like a fine change to me, though I don't think it will prevent the problem with submit buttons (or is that not a problem at all at this point?)

However we should use form_clean_id() around the whole ID attribute, not just the node ID:

form_clean_id('edit-actions-' . $node->nid)

As form_clean_id() keeps track of all the used IDs based on the whole ID, not just a part of it.

Bartezz’s picture

As form_clean_id() keeps track of all the used IDs based on the whole ID, not just a part of it.

Yeah sounds better to use it that way then :) Do you need me to cook up a new patch?

I don't believe the submit button is an issue anymore. It was before, but the input elements now have unique idea's. Can't find the issue where this was discussed. The only problem I had, other than the above, with webform, were the IDs used in the wrapper divs. So I used the theme_webform_element_wrapper() in my template.php to also make sure the ID's of the wrappers were unique via form_clean_id(); @ webform.module line #2469

Cheers

caspercash’s picture

I think you will be able to assign unique id to a webforms submit button manually by using this piece of code inside hook_form_alter:

$form['actions']['submit']['#id'] = 'edit-submit-webformname';

Hope this helps!

Bartezz’s picture

@caspercash; true, but using form_clean_id() in the module would prevent the need of custom modules having to use hook_form_later. A better solution IMO...

Cheers

caspercash’s picture

@Bartezz: i too don't want to use a custom module just to assign unique id for the submit button but there is a bit of a problem when dealing with the unique ids. You see, in my situation, I created a webform and I made it available as a block. When I view the webform(page), the submit button id of the webform in the page is 'edit-submit' and the submit button id of the webform in the block is 'edit-submit-1'. As I have observed, the submit button id of the block changes whenever there is another submit button in the page. When there is non, it returns back to 'edit-submit'.

I've created a javascript code that will only affect the submit button inside the webform block. This javascript code is executed whenever the webform block is displayed. Now my problem is, I cannot make use of my javascript code if the submit button id changes from 'edit-submit' to 'edit-submit-1'. This is the reason why I did create a custom module to assign unique id to the submit button inside the webform block.

I have an idea, maybe quicksketch may be able to add an additional field for the settings of the webform that will allow administrators to assign ids on each field. It is just an idea though. For me, it would be great if it will be implemented.

Bartezz’s picture

@caspercash: not to be harsh but an additional field for an ID setting to solve your issue is way over the top! Just alter your jQuery/JS element selector synax!

Instead of $('#edit-submit-1').click(function() {... do something like $('div#block-id input.edit-submit').click(function() {...

Cheers

caspercash’s picture

@Bartezz: I am sorry if its way over the top. I just wanted to share my problem and suggested a way to have more control (assigning unique IDs) of the webforms submit button instead of controlling it inside hook_form_alter.

BTW, thank you very much on your suggestion! I think it might work! I will have to try it then.

Cheers!

quicksketch’s picture

quicksketch’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

This probably won't be fixed in the 6.x-3.x version. In Drupal 7, this is fixed in the 4.x version by #2059215: Replace use of IDs to classes on Webform wrappers to avoid duplicate IDs, which couldn't be backported anyway because it would break existing theming.