the upload_js function stores the updated form back into the cache before invoking hook_form_alter, because of this modifications made to the form in hook_form_alter won't work correctly when submitting the form as the form that is stored in the cache is different from the one displayed to the user. The attached patch seems to fix this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mkruisselbrink’s picture

btw, the same issue seems to apply to 7.x as well, although I haven't actually tested that.

mkruisselbrink’s picture

Version: 6.1 » 7.x-dev

change version to 7.x as the bug exists in both 6.x and 7.x

mkruisselbrink’s picture

FileSize
1.02 KB

updated patch with no more trailing whitespace

mkruisselbrink’s picture

FileSize
1.02 KB

update patch to cleanly apply after string-concatenation-operator spacing changes.

maartenvg’s picture

Patch still applies correctly, but with some offset. No Simpletest fails are introduced after applying the patch.

Can you describe step by step how to reproduce the bug, because I haven't been able to check whether it actually fixes the bug? Thnx.

drewish’s picture

mkruisselbrink, do you have a simple example module that we could use to test this out?

mkruisselbrink’s picture

FileSize
1.12 KB
967 bytes

Attached a simple example module to test this, and a updated patch against a newer cvs revision. To reporoduce the problem, install this module, and than (without saving in between) upload a new attachment for a node, and enter a value in the Test field for an attachment. Without the patch applied, this will result in some warnings when you save the node; with the patch applied you'll get correct messages showing what values you entered in those fields.

drewish’s picture

sorry for waiting so long on this but i just got around for it and couldn't test this because i'm getting fatal errors when saving nodes with uploads attached (Fatal error: Exception thrown without a stack frame in Unknown on line 0)... need to do some checking to see if i can figure out the cause.

drewish’s picture

i can confirm that the fix works but i don't know enough about the code to say that it's the correct fix.

Status: Needs review » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Needs review
mkruisselbrink’s picture

Status: Needs review » Reviewed & tested by the community

Marking this issues as reviewed, as after all it was reviewed and no problems were found.

Damien Tournoud’s picture

Status: Reviewed & tested by the community » Needs review

Rule number 1: never, ever, mark your own patches as RTBC.

Damien Tournoud’s picture

To be perfectly consistent, I think the call to drupal_alter('form', <the upload partial form>, array(), 'upload_js'); should be moved to _upload_form(). This way, we will insure that the form alter is consistent between javascript and non-javascript mode.

This definitely requires more discussion.

mkruisselbrink’s picture

that might be a better fix, but it would be a change that potentially breaks/changes behavior of modules that current alter both the node-edit form and the upload_js form, as that change would mean that the already altered upload_js form would be inserted in the node-edit form. If that is okay as far as behavior changes go, I'll make a new patch that does that. I just tried to make this patch as non-intrusive as possible.

Damien Tournoud’s picture

@mkruisselbrink: as far as I understand, this never worked (ie. the form was always form_altered *after* being cached back), so it can't possibly break anything :)

By the way, if you move the form_alter to _upload_form, please rename the form_id from 'upload_js' to 'upload_form'.

Damien Tournoud’s picture

Status: Needs review » Needs work

CNW as per #14 and #16.

webchick’s picture

Version: 7.x-dev » 6.x-dev

Upload module has been removed from Drupal 7. Moving down to 6.x.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.