OK, this is a weird one. I've got 2 modals. In the first one I invoke user_register_form, in the second one I invoke user_pass. When the form validation fails, interestingly the user_pass form's #id changes to user-pass--2, therefore the CSS ID of the form changes too, to user-pass--2. It doesn't change when submitting the other modal that displays the registration form.

Any help would be great.

Thanks

Rob

Comments

merlinofchaos’s picture

This is probably happening because Drupal records what HTML IDs are on the page and form api guarantees form IDs are unique. When I'm doing stuff in the modal, I often unset...I think it's $_POST['ajax_html_ids'] to ensure this doesn't happen, since modals are pretty insulated from everything else anyway.

This is probably going to be a bigger and bigger problem moving forward. I think this probably just needs to be documented; we shouldn't do it automatically but document that people may need to do it.

thetoast’s picture

I guess this is the drupal function that's called to give unique ids drupal_html_id($id) and looking at that function you're correct with $_POST['ajax_html_ids']. You can see a quote at the bottom from Ryan Szrama warning about the same behaviour.

But this still doesn't make sense as to why it doesn't rename the id for the user_register_form. To add to Robert's issue summary, the renaming of the id also happens with user_login........what makes user_register_form so special?

rvarkonyi’s picture

Yeah, that's what I don't understand either. Anyway, I'll try and unset $_POST['ajax_html_ids'] and see what happens.

Thanks for the help.

Rob

rvarkonyi’s picture

Status: Active » Closed (fixed)

Yep, done it. Thanks

tim.plunkett’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review
Related issues: +#1305882: drupal_html_id() considered harmful; remove ajax_html_ids to use GET (not POST) AJAX requests
StatusFileSize
new677 bytes

I just hit this again in #1675522: Remove button broken if form is rebuilt (via ajax or failed validation).

field_collection has this same pattern (already in CTools and Views) as written by @merlinofchaos, and it solves my problem, and is unlikely to cause additional adverse side-effects.

tim.plunkett’s picture

StatusFileSize
new1.5 KB

Per @dawehner's request, making this opt-in.

  • Commit e720f61 on 7.x-1.x authored by tim.plunkett, committed by japerry:
    Issue #1315900 by tim.plunkett: Add reset_html_ids option to stop form...
japerry’s picture

Status: Needs review » Fixed

Reviewed and looks good, per Tim. Committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.