Could someone explain the reasoning behind the first criteria (!form_get_errors()) in the following code in comment.module:

  // Only show save button if preview is optional or if we are in preview mode.
  // We show the save button in preview mode even if there are form errors so that
  // optional form elements (e.g., captcha) can be updated in preview mode.
  if (!form_get_errors() && ((variable_get('comment_preview_'. $node->type, COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL) || ($op == t('Preview')) || ($op == t('Save')))) {
    $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 19);
  }

It's a bit confusing for the user if the submit button disappears just because the form has an error.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gpk’s picture

>It's a bit confusing for the user if the submit button disappears just because the form has an error.
Does this actually happen?

I find it doesn't, and I think the reason is that forms are cached (in 6.x) so this code doesn't actually get run in general if there are form errors. Quite what happens in 5.x I'm nor sure.

For info the code above comes from http://api.drupal.org/api/function/comment_form/6.

jrao’s picture

It doesn't happen if you're just using comments module as it is, the reason I think is because comment_validate (which fills form errors) is called after comment_form, so when the form_get_errors() is called inside comment_form for the 1st time, there's always no error. This only works if you get the comment form only once in a request, if for any reason you want to get the comment form a second time (for example, if you want to display the comment form separately in other places in the theme), then form_get_errors() will return the validation errors and submit button will be missing.

sun’s picture

Version: 6.14 » 7.x-dev
Category: support » task

I agree that this is confusing. Still an issue in D7. (Although I recently added a special condition for comment administrators to always be able to submit)

sun’s picture

Title: Why hide comment save button when form has error? » Comment save button disappears on validation error in any form
Category: task » bug
sun’s picture

Status: Active » Needs review
FileSize
1.49 KB

So let's remove that weirdness. I guess/hope that some test will fail though. Otherwise, this isn't covered by tests yet, and so we'd remove a untested feature.

sun’s picture

#5: drupal.comment-save-button.5.patch queued for re-testing.

sun’s picture

Assigned: Unassigned » sun

Status: Needs review » Needs work

The last submitted patch, drupal.comment-save-button.5.patch, failed testing.

sun’s picture

Title: Comment save button disappears on validation error in any form » Comment "Save" button disappears on form validation error
Status: Needs work » Needs review
FileSize
1.43 KB

Re-rolled against HEAD.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

looks like right fix (remove check for errors). please wait for green before commit.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

I think it is a left-over from the old error handling pre-"form API" times. Committed this patch to CVS HEAD.

mrwbsn’s picture

Status: Fixed » Needs review

#9: drupal.comment-save-button.9.patch queued for re-testing.

sun’s picture

Status: Needs review » Fixed

Please do not re-test already committed patches.

Status: Fixed » Closed (fixed)

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

xvoid@drupal.org’s picture

Is this patch already in Drupal 6 core?

I am using pressflow 6.20 and had the same problem as mentioned above.
Used the trick from drupal.comment-save-button.9.patch to fix it, but found it strange that this patch is not in core of Drupal 6.