In comment_upload.module around line 124 I run into the following code comment:

// Rape the comment form.
// Comment_form was not build to rebuild a form and fetch values from $form_state.
// To preserve changes made by the user, we build the part of the form we just received,
// mapping $_POST values to #default_values.
// Because rebuild is TRUE, $_POST has been validated. Nevertheless this is insane.

(emphasis added)

This has been in the comment_upload module code for ages. I hope you all agree this should be fixed. The culprit actually is the comment_upload_value_to_default() function. This recursively rewrites every #default_value in the form array to #value. (wait... WHAT?)
Rather than rewriting the entire comment form I'd prefer to create a solution whereby only the file upload itself is handled.

this is evil:

foreach (element_children($build_form) as $key) {
  if (isset($form[$key]) && isset($build_form[$key]['#value'])) {
    $form[$key]['#default_value'] = $build_form[$key]['#value'];
  }
}

I was up all night trying to figure out how to debug a date field in the comment form (via time_tracker). So when I figured out the above in comment_upload which was causing problems, I thought it best to report this instead of trying to build a workaround in time_tracker.

Comments

dww’s picture

Category: task » bug

Yeah, that sounds like a bug. I don't have any memory of this code, or exactly what's going on here. I believe that's netaustin code, but I'm not sure. I don't have time/bandwidth to investigate or fix, but if you come up with a cleaner and working solution, I'll definitely try to review/test/commit ASAP. comment_upload should not be trashing the entire comment form like that.

dww’s picture

Title: Let's not "Rape the comment form" » comment upload rewrites entire comment form to set #default_value from #value breaking other modules

Better title. While we're at it, I'd be very happy to remove the code comment about "rape". Rape is no joke, and I'd rather not take it lightly in this way.

basvredeling’s picture

I agree with your remark about keeping the code comments civilised.
I'll see if I can muster up an alternative method. It probably won't be ready tomorrow though.

cgrant3d’s picture

Any update on this issue? I'm having a similar problem where mollom gets wiped out because I have comment upload enabled on comments...