I've got three pages worth of avatars within the user registration/profile editing form. If I choose one of the images on the first page, the form validates just fine, but if I go to the second or third page and submit, I get the error "An illegal choice has been detected. Please contact the site administrator."

This seems to be happening because the form_build_id of the form that gets submitted refers to an outdated version of the form, which only includes the first page of avatar images in the #options array for the "select_avatar" element.

My workaround for this error was to add the following two lines to avatar_selection_pager.js:

var buildID = $(data).find("input[name='form_build_id']").val();
$('#' + form_id + " input[name='form_build_id']").val(buildID);

It surprises me that this error hasn't been reported before - has anyone else run into this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

attishu’s picture

Hi,

I have the same issue. Just I'm not a java script expert... please can you tell me, where you add this two lines?

Thank you.

joelstein’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

I cannot reproduce this bug in a vanilla installation of Avatar Selection (latest dev). Please let me know how you have the module configured at admin/config/people/avatar_selection. Also, are you selecting an avatar on the first page of results and then paging to the 2nd page and clicking submit? Or are you paging, then selecting an avatar, and then clicking submit?

If you can show me steps to reproduce this, I'll get it fixed.

DrupalOnFire’s picture

Hi attishu,
may be it's too late, but I hope this will be helpful to someone else also.
Open the avatar_selection_pager.js and place the above code after this line
$.get(url, function(data, status) {

nategasser’s picture

I had the same problem and litzastark's workaround worked for me. The error occurred after moving to page 2, clicking an icon, and hitting save. Thanks!

ganchito55’s picture

I had the same problem and I have also detected that is generated by ajax. When I click in page 2, ajax loads the new avatars in the same page without navigate to "edit?page=1" and the error appears. If you go manually to "edit?page=1" and select an avatar, it works.

cyptm’s picture

I was able to replicate this issue. Test it with the above proposed solution and create the attached patch for it.

cyptm’s picture