Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#9 | drupal.comment-save-button.9.patch | 1.43 KB | sun |
#5 | drupal.comment-save-button.5.patch | 1.49 KB | sun |
Comments
Comment #1
gpk CreditAttribution: gpk commented>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.
Comment #2
jrao CreditAttribution: jrao commentedIt 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.
Comment #3
sunI 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)
Comment #4
sunMarked #496836: comment submit button dissappears if there's another form on the same page submitted with error as duplicate of this issue. Which turns it into a real bug.
Comment #5
sunSo 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.
Comment #6
sun#5: drupal.comment-save-button.5.patch queued for re-testing.
Comment #7
sunComment #9
sunRe-rolled against HEAD.
Comment #10
moshe weitzman CreditAttribution: moshe weitzman commentedlooks like right fix (remove check for errors). please wait for green before commit.
Comment #11
Dries CreditAttribution: Dries commentedI think it is a left-over from the old error handling pre-"form API" times. Committed this patch to CVS HEAD.
Comment #12
mrwbsn CreditAttribution: mrwbsn commented#9: drupal.comment-save-button.9.patch queued for re-testing.
Comment #13
sunPlease do not re-test already committed patches.
Comment #15
xvoid@drupal.org CreditAttribution: xvoid@drupal.org commentedIs 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.