using d7 dev (2010-May-30) and received following error: Notice: Undefined index: format in comment_preview() (line 1966 of ***modules/comment/comment.module).
Steps to recreate error:
(1) manage comment fields of a content type, edit comment_body. (2) select "Plain text" under Text processing. (3) leave defaults and/or change "format" under Comment Display. (4) view an existing node and create/edit comment. (5) click preview button.
Note: This only occurs with settings above, and clicking preview button. Line 1966 (as of 5/30/10) from comment.module is: $comment->format = $comment->comment_body[LANGUAGE_NONE][0]['format'];. Similar is also on line 2093.
Thanks a million!
Comments
Comment #1
dinknaround commentedUpdate: I commented out line 1966 //$comment->format = $comment->comment_body[LANGUAGE_NONE][0]['format']; and it stopped the error and allowed the proper formatting during preview, as plain text and stripping html by field module/text module. Although I notice that the textarea box retains the html (but that's probably a whole other issue). As far as similar on line 2093, haven't touched it yet.
Comment #2
aspilicious commentedTried a fresh installation??
With the new manage field screen you need a fresh install.
Comment #3
dinknaround commentedYes, this was on a fresh install of the D7-dev released on 5/30. I did notice the new options when managing a node content's fields. I'm not an expert, but I really think it has something to do with the code in the comment.module's function comment_preview. Don't understand why this line is needed $comment->format = $comment->comment_body[LANGUAGE_NONE][0]['format'];. The proper format gets picked up and set in variables without that line. I didn't notice comment.module creating a custom format types.
If you referring to a D7-dev after 5/30, I'll try it out.
Comment #4
dinknaround commentedaspilicious - I did a fresh install today (6/3/2010). And still have the same error. So basically, when managing the comment field's body, "Plain text" can "NOT" be selected a format, and matching the field's display view as "Plain text" does not fix the error to undefined index.
Comment #5
aspilicious commentedI'll try to reproduce
Comment #6
aspilicious commentedNotice: Undefined index: format in comment_preview() (line 1960 of C:\xampp\htdocs\drupal\modules\comment\comment.module).
bingo...
Ok let's make those steps more readable
1) go to manage comment fields of article
2) edit comment_body.
3) select "Plain text" under Text processing
4) Change "format" under Comment Display. ==> Plain Text
5) view an existing node and create comment.
6) click preview button.
Comment #7
dinknaround commentedOMG Yes! Thank you, I'll remember to keep it simple in the future.
As for the issue, anybody out there with a solution?
Comment #8
yched commentedThis $content->format sounds like a thing from the past. The format of the text in the 'comment_body' field is not an inherent data of the comment itself. On a quick inspection (but this should probably be double checked), no other part of comment.module makes use of it.
On a related note, comment_submit() also assumes a) that there is a 'comment_body' field, and b) that it is 'formatted text' and not 'plain text'. Both assumptions can be wrong.
Comment #9
damien tournoud commentedNote that $comment->format is *not even* in the schema; we might just be able to remove those lines completely.
Comment #10
damien tournoud commentedAbout comment_submit(): we need to generate the subject from the comment itself. Could we just call comment_build_content(), convert it to plain-text and use the begining of that?
Comment #11
yched commented"Note that $comment->format is in the schema"Really ? I can't see this.
[edit: Damien fixed his post]
"About comment_submit(): we need to generate the subject from the comment itself. Could we just call comment_build_content(), convert it to plain-text and use the begining of that?"
Sounds good to me.
Comment #12
damien tournoud commentedThat was a typo.
Comment #13
dinknaround commentedActually, I currently have the $comment->format commented out (a hack, I know, bad) but it works with no problems for me. Doesn't comment module just hook into fields defined in field module...which I believe picks up the proper formatting? I'm in NO WAY an expert, but it's working for me this way.
Comment #14
dinknaround commentedBack again, still same issue, now with official d7 release.
It's the line from comment_preview()
$comment->format = $comment->comment_body[LANGUAGE_NONE][0]['format'];
Did a variable dump, found that ['value'] and ['format'] will be applied with the module's default settings. But only ['value'] will be applied if settings changed to "plain text".
And yes, I tried this by changing both format settings in edit field and manage display, and then changing one but not the other.
Comment #15
sTaX-1 commentedI have the same issue.
But if I allow filtred or plain text/html it works and the 'format'-key exist.
Comment #16
mattyoung commented#9:
>Note that $comment->format is *not even* in the schema; we might just be able to remove those lines completely.
This fix the problem here. But the real problem is the "format" key should always be there. If not, how to know what the format is on comment validate?
Also, the "format" key is in the node body. Things should work the same way here.
EDIT: never mind. I see what's going on from #6. So if text processing is "Plain text", there is no format.
Comment #17
dinknaround commentedWell, if I'm understanding this right, $comment->format is in the schema. See see field_data_comment_body in the db, the field is comment_body_format. Does the comment module code pretty much mimic the node module? This issue doesn't happen when selecting plain text as the format for the body field in node type edit form. And the field_data_body table also has body_format. Doesn't the text.module handle the formatting?
Comment #18
dinknaround commentedWell, I still can't figure why on line 2065 the comment.module has
$comment->format = $comment->comment_body[LANGUAGE_NONE][0]['format'];. Is it to ensure format type gets added to the db at field_data_comment_body? Doesn't the field module handle this when it's functions are invoked in comment_save? And default in db is NULL I believe.Then on line 2183 the comment.module has
$comment->subject = truncate_utf8(trim(decode_entities(strip_tags(check_markup($comment->comment_body[LANGUAGE_NONE][0]['value'], $comment->comment_body[LANGUAGE_NONE][0]['format'])))), 29, TRUE);. This is to populate an empty $comment->subject, (the subject field on the form). Since this is a textfield, and basically the title of a published comment, shouldn't this be "plain text" anyway?Here is a really quick workaround I'm using right now instead of hacking the core, I use a small custom module for a few of my alters anyway. Anyone have an opinion of this? Or a better way?
Comment #19
droplet commentedAgreed
if not there, check_markup called filter_fallback_format and returns right filters.
I guess we need to add a variable for it to set the right fields
add a temporary patch for it, somebody may needed.
Comment #20
mattyoung commentedWe need to somehow know all of these to write comment validate code. The same applies for node validate. Most people probably will not know and write buggy code that works most of the time. Ideally, these should be documented. For node validate, we can put this information in
hook_node_validate(). Unfortunate, there is nohook_comment_validate(). Maybe we should put this back in so these thing can be documented there. See #512492: Remove hook_comment_validate() and #974118: hook_comment($op == 'validate') has gone.Comment #21
agence web coheractio commentedI think patch in #19 shall read
$comment->comment_body[LANGUAGE_NONE][0]['format'] = NULL;
(without the ' ' around NULL)
Laurent
Comment #22
yugongtian commentedMy content type do not use subject ,and I delete the comment body field .
Create a new text field .to limit Maximum length *
But when I try to replay the content get ero. I search it in here.
I was try # 19 or # 21 ,but get also this ero
Notice: Undefined index: value in comment_submit() (line 2185 of E:\wamp\www\test9\modules\comment\comment.module).
And I try to delete 2183 line it's ok : )
$comment->subject = truncate_utf8(trim(decode_entities(strip_tags(check_markup($comment->comment_body[LANGUAGE_NONE][0]['value'], $comment->comment_body[LANGUAGE_NONE][0]['format'])))), 29, TRUE);
I 'm not coder so,any helps ?Let me know why?
Thanks.
Comment #23
geerlingguy commentedI'm hitting this error on a couple of my sites too:
Bumping issue back to -dev, against which patches should be made.
Possible duplicate / merge-able issue: #1170948: Error Notice with Comments.
Comment #24
lyricnz commentedHere's the patch from issue #1170948: Error Notice with Comments which fixes it. Closing other as duplicate.
Comment #25
RedTop commentedimplemented patch, works beautifully.
D7.2
Comment #26
marcingy commentedComment #27
yched commentedYou can't run check_markup() if format is NULL.
If the field is "formatted", check_markup() should be used, if not check_plain() should be used.
Comment #28
geerlingguy commentedProbably should fix 8.x first, then backport.
Comment #29
lyricnz commentedUpdated patch, $comment_body is just an alias to make the following code saner.
Comment #30
amateescu commentedLooks good to me. Tested with latest -dev and the notice is gone.
Comment #31
webchickWell! That code is certainly much easier to read now.
However, it'd be nice to get #6 captured as an automated test.
Comment #32
lyricnz commentedComment #34
lyricnz commentedPatch in #32 is a test, that fails without the patch. Attached is #29+#32
Comment #35
lyricnz commentedSwapped ternary for if/else, and updated test description comment. :Q
Comment #36
catchLooks great, comes with a nice test too.
Comment #37
webchickPerfect, thanks!
Committed to 8.x and 7.x.
Comment #38
geerlingguy commentedSo, removing tag...?
8.x commit: http://drupalcode.org/project/drupal.git/commit/d443880
7.x commit: http://drupalcode.org/project/drupal.git/commit/0f9c135
Comment #39
aspilicious commentedWebchick KILLS you if you remove that tag. The strange tag switching in webchicks post is something on drupal.org. She didn't do it. :)
But we can remove the needs tests.
Comment #40
geerlingguy commented... but it's already been backported... right? Or does she use that tag for release tracking?
Comment #41
webchickI like to keep it there because it's issue metadata that's important for historical reasons, so I can see how many "needs backport" issues got fixed. We also don't remove "Performance" just because an issue got fixed, for example. :)
Comment #43
BeaPower commentedHi is this a fix if you removed comment form? - using drupal 7
Comment #44
katd commentedUm, the fix for preview still seems to be missing?
Comment #45
Patricia_W commentedI'm getting this error in Preview mode:
Notice: Undefined index: format in comment_preview() (line 2043 of /home/content/p/w/a/pwarwick/html/modules/comment/comment.module).
Comment #46
_kash_ commentedNotice: Undefined index: format in comment_submit() (line 2164 of /xxxxxxx/modules/comment/comment.module).
Comment #47
mototribe commentedI get an error: Undefined index: format in comment_preview() (line 2043 .... when previewing a comment (plain text format)
Drupal 7.8
Comment #48
geerlingguy commentedStill needs to be fixed in head first...
Comment #49
no2e commentedI think there is a fix which needs testing:
#1371682: Undefined index: format in comment_preview line 2053
Comment #50
chi commentedSorry, crossposting.
Comment #51
negativefix commentedCame across the same issue with the clean installation of drupal via drush. Although I don't desire, I had to switch text processing of comment body field to 'Filtered Text' to get rid of the error message.
Comment #52
simon147 commentedI confirm comment #51: That this bug seems to still exist (Drupal 7.20). Only thing: Instead of line 2065 it's now line 2069.
Comment #53
lyricnz commentedPlease don't reopen ~2 year old issues - create a new one, or add comments to one of the open duplicates.
Comment #54
David_Rothstein commentedI think this could legitimately be reopened since the original bug was never fixed. The bug was about comment_preview(), but the committed patches only addressed comment_submit().
Nonetheless, there's a new issue at #2077901: Comment Preview Error for Plain Text (Undefined index: format in comment_preview()) so might as well just use that one. But I think there's a lot of discussion here that is relevant for that issue...