# Undefined index: format in _text_sanitize()

 Project: Views Version: 7.x-3.7 Component: Miscellaneous Category: bug report Priority: normal Assigned: Unassigned Status: needs work Issue tags: text format, unsanitize

## Issue Summary

As mentioned briefly in this comment, when working with a text field (the body) in my view, I'm getting the following error:

Notice: Undefined index: format in _text_sanitize() (line 319 of /public_html/modules/field/modules/text/text.module).

This also is most likely the reason that I'm seeing tags when viewing a textfield in my view. For example, instead of html formatted output, I'm seeing something like

<p>my text shows here, including the paragraph tags</p>

### #1

Does this happen only when aggregating a field?

### #2

Honestly, I'm still figuring out what "aggregating" a field means :) The fields are grouped and the field does say "Aggregation Settings" next to it...so yeah, I suppose it's aggregated.

### #3

Aggregating means taking the results of several fields in a group and running an aggregation function on them, such as sum or count or average. It's required when 'aggregation' setting is checked in the advanced settings.

### #5

Can you describe how to reproduce the problem easy?

This would really help to fix the problem.

### #6

Dereine: I had a fields based view where I used the "Group by" functionality. Then, as merlin mentioned, you choose the 'aggregate' checkbox under advanced to see this behavior.

I unchecked aggregate and the error went away...my tag problem also was resolved.

### #8

+1

Happens when I enable aggregation while "Content: Body" is a displayed field.

### #9

Hello all,

I have the same error.

Notice: Undefined index: text_processing in _text_sanitize() (Zeile 319 von /is/htdocs/wp1191537_HP1AJE6ECC/www/metropolnews-mrn/modules/field/modules/text/text.module).    Notice: Undefined index: value in _text_sanitize() (Zeile 319 von /is/htdocs/wp1191537_HP1AJE6ECC/www/metropolnews-mrn/modules/field/modules/text/text.module).

Everything went fine until i added a Taggingfield to my Block-View and did some rearranging.

### #10

And after I did some Work with the fields, like Rewrite Output and things like that - the Error-message disappeared.

### #11

Note: I got same error after adding computes field to the content type and view.
Changing the field formatter to plain text the notices disappeared.

### #12

The same error. Subscribe.

subscribe

subscribe

### #15

By isolating the field that was causing the error, due to the lack of that field I was able to correct this.

I went into views, edited the field's properties, and saved. It is now supplying the needed index, so the errors go away.

In my case this was a field that was once a text field, then was changed into a list. I am fairly certain that I did the view edits that caused this after it became a list, but hopefully that will help someone else resolve the root cause of this.

### #16

In my case this was a field that was once a text field, then was changed into a list

Actually no wonder that this caused an error :)

### #17

I am getting this error, and I did not convert a text field to a list, it is simply happening when I have a body field in a view that has aggregation turned on.

### #18

Seems to actually happen when choosing "value" as the group by characteristic for body field.

### #19

it is simply happening when I have a body field in a view that has aggregation turned on.

Seems to actually happen when choosing "value" as the group by characteristic for body field.

Based on this info i've tried to reproduce the problem and i couldn't.
Could someone preovide an export?? (see, for example the file att.)

AttachmentSizeStatusTest resultOperations
view-export.txt5.48 KBIgnored: Check issue status.NoneNone

### #20

I created a View that pulled several fields from a content type, which worked great. Then I had to change one of the fields in the content type from a free-text field to a text selection list, using the same field name.

After that, I was seeing this error everywhere the View was displayed.

I deleted the original field from the View and added it back in (even though it was the same name and was still a text field) and the error was gone.

Not sure if that helps you identify the problem, but it fixed my issue.

### #21

Here is a print screen of the problem: http://imageshack.us/photo/my-images/502/viewserror.jpg/

and attach the export of the view

AttachmentSizeStatusTest resultOperations
views_exp.txt16.9 KBIgnored: Check issue status.NoneNone

### #22

Ataxia is right. I delete the field and add it again to the view and the problem is gone.

### #23

I deleted the original field from the View and added it back in (even though it was the same name and was still a text field) and the error was gone.

Ataxia is right, I deleted the field I change and add it again to the view and the problem is gone.
Here is attach the export of the fix view and the problem was here:
$handler->display->display_options['fields']['field_cena']['type'] = 'text_default'; and now look like: $handler->display->display_options['fields']['field_cena']['settings'] = array(  'thousand_separator' => ' ',  'decimal_separator' => '.',  'scale' => '2',  'prefix_suffix' => 1,);

I hope this can help for understand where is the problem and how to fix it.

Greetings

AttachmentSizeStatusTest resultOperations
views_fix.txt16.93 KBIgnored: Check issue status.NoneNone

### #24

I had the same problem after adding the date field to the article content type and it wouldn't go away. I do have a backtrace which will hopefully help. Here's the result:

Notice: Undefined index: format27  Line: 21,  File: /index.php,  Function: menu_execute_active_handler26  Line: 518,  File: /includes/menu.inc,  Function: drupal_deliver_page25  Line: 2438,  File: /includes/common.inc,  Function: drupal_deliver_html_page24  Line: 2550,  File: /includes/common.inc,  Function: drupal_render_page23  Line: 5505,  File: /includes/common.inc,  Function: context_page_build22  Line: 248,  File: /sites/all/modules/context/context.core.inc,  Function: execute21  Line: 222,  File: /sites/all/modules/context/plugins/context_reaction_block.inc,  Function: block_get_blocks_by_region20  Line: 316,  File: /sites/all/modules/context/plugins/context_reaction_block.inc,  Function: block_list19  Line: 352,  File: /sites/all/modules/context/plugins/context_reaction_block.inc,  Function: _block_render_blocks18  Line: 834,  File: /modules/block/block.module,  Function: module_invoke17  Line: 794,  File: /includes/module.inc,  Function: call_user_func_array16  Function: views_block_view15  Line: 639,  File: /sites/all/modules/views/views.module,  Function: execute_display14  Line: 1132,  File: /sites/all/modules/views/includes/view.inc,  Function: execute13  Line: 53,  File: /sites/all/modules/views/plugins/views_plugin_display_block.inc,  Function: render12  Line: 1011,  File: /sites/all/modules/views/includes/view.inc,  Function: execute11  Line: 992,  File: /sites/all/modules/views/includes/view.inc,  Function: _post_execute10  Line: 583,  File: /sites/all/modules/views/includes/view.inc,  Function: post_execute9  Line: 613,  File: /sites/all/modules/views/modules/field/views_handler_field_field.inc,  Function: set_items8  Line: 770,  File: /sites/all/modules/views/modules/field/views_handler_field_field.inc,  Function: field_view_field7  Line: 934,  File: /modules/field/field.module,  Function: _field_invoke_default6  Line: 375,  File: /modules/field/field.attach.inc,  Function: _field_invoke5  Line: 198,  File: /modules/field/field.attach.inc,  Function: field_default_view4  Line: 210,  File: /modules/field/field.default.inc,  Function: text_field_formatter_view3  Line: 264,  File: /modules/field/modules/text/text.module,  Function: _text_sanitize2  Line: 319,  File: /modules/field/modules/text/text.module,  Function: _drupal_error_handler1  Line: 2172,  File: /includes/bootstrap.inc,  Function: _drupal_error_handler_real0  Line: 88,  File: /includes/errors.inc,  Function: _drupal_log_errorin _text_sanitize() (line 319 of /modules/field/modules/text/text.module).

### #25

I've changed this to active as I suspect I've tracked down at least some of variables that are the root cause of this bug but if you still can't duplicate it let me know what I can do next.

I tried deleting then adding the content body field as mentioned above and no effect but left the aggregate settings and body field at their defaults. I then looked a little closer and saw that it defaulted grouping on "value" which didn't make any sense to me since value would be the body text (at least in my case it makes no sense). I then changed the grouping from the default to Item ID and the error went away (I assume Item ID's are unique so there was no grouping that could happen).

I then looked at the field side and noticed that formatter was set to default. I changed it to plain text, changed the grouping back to value in the on the aggregation side and no error. I think what this is saying that somehow the body text is being left without a formatter when it's on default and therefore the grouping when set to value doesn't have enough information to work with since there is no formatter to go through and this lack of information goes all the way through to where the error happens.

Does this work for anyone else?

I tracked this down to the $entity variable in set_items() in views_handler_field_field.inc on the content body field (line 764). This$entity variable gets passed (at least in part) all the way through to _text_sanitize() . The variable in _text_sanitize() that causes the error looks like this for the body field:

array(1) {  ["value"]=>  string(143) "<iframe frameborder="0" height="1920px" scrolling="no" src="http://mysite.com" style="overflow-y: auto;" width="100%"></iframe>"

### #26

Two more items that I just noticed just:

• The error doesn't show up from the view preview, only on the properly rendered page
• If I use the either of the other two formatters (summary/trimmed) the error returns and an additional error as well (below)

Notice: Undefined index: format in text_field_formatter_view() (line 279 of modules/field/modules/text/text.module).

### #27

I can confirm that I did the same thing in Ataxia's (#20) comment: I created a text field, made a *page* view with the text field, changed the field to a list with the same machine field name and didn't edit the view.

When I removed and re-added the field the problem went away.

It might be specific to page views, if that helps narrow down how to reproduce it. Not sure.

### #28

Are you sure this is a Views related problem? I have a custom content type that after moving from D6 to D7 (running on 7.12) started giving this error: Notice: Undefined index: format in _text_sanitize() (line 319 of ....modules/field/modules/text/text.module). The content type has nothing to do with views, but does have quite a few custom fields.

When I first migrated into D7 I had quite a few problems with these custom fields - fatal errors on the integer fields and I resaved each of them which seemed to clear all that up. But now I get the undefined index: format in the _text_sanitize function.

So, not sure if that adds any pertinent info to the problem but I'll start watching this thread. Thanks for any insights.

### #29

Grouping by value on a text field when using aggregation triggers the problem for me - text field html tags are escaped in both preview and final render, and I get the text format error when the view is rendered. This is a block view, so it's not restricted to pages.

Grouping by entity ID fixes it.

### #30

I had the same issue. Grouping "body" field in the view by "Entity ID" fixed it.

### #31

@Toddv: Regarding,

"Are you sure this is a Views related problem?"

Have a look at the backtrace in #24, it's clearly going through views. My install also is a clean 7.x install. No upgrading from D6.

### #32

Ah, right you are.

### #33

Same here:

Notice: Undefined index: format in _text_sanitize() (line 319 of C:\drupal\modules\field\modules\text\text.module).Notice: Undefined index: format in _text_sanitize() (line 319 of C:\drupal\modules\field\modules\text\text.module).

After aggregating body field. #30 doesn't work for me. How ever changing body field Formatter to Plain Text fix it. Off course its not a solution.

### #34

Just met the same problem with aggregating field. Subscribe.

### #35

 Status: active » fixed

If you use aggregation you should better change the aggregation setting of the field and add the format field there as well. This should fix the issue here.

### #36

 Status: fixed » needs work

I agree that the problem seems to be solved through enough people saying what's happening for the issue to be known and understood.

However, shouldn't there be either a code change or at the very least some documentation added to the module somewhere so that when you turn on aggregation you are either programatically locked out from doing the wrong combination of options or at least there is some text to tell you what you need to do right?

To me posting the error in drupal.org or a web search engine to pull up this page to learn what you have to do is not exactly a fix. Even if it's not feasible to change the code wouldn't some warning or info text somewhere when you first turn on aggregation be reasonable and plausible solution?

"Warning, not selecting the appropriate text filter could result in "warning" messages in your log table".

or something like it.

### #37

When this happens with any text field, simply changing the format from "default" to "plain text" solved this problem.

### #38

@kannary100, Yes, I think we have established that changing the filter from default solves it. But like I said in #36, something that tells people this when they turn on aggregation instead having to search to find out what's going wrong would be appropriate.

### #39

I have a View with six attachments and I get exactly the same error messages whenever any one of these attachments returns a result. It is fine when no results are returned and if more than one attachment returns a result then I get more than one set of error messages as you might expect.

However, I am not aggregating anything on any of these attachments or, indeed, on the main Page. Changing the format has no effect (most of my fields are hidden anyway).

### #40

my problem also was caused by the aggregation of the field.
1 field gave error - field Content: body. so i set another Aggregation Group column, by default there was "format", so i select "Entity ID", thats all.

### #41

In my case it was an aggregation settings for the actual field that solved it. I used a text field in the view that for some reason the default aggregation settings did not included the text format. That obviously offended (at rightfully so) the _text_sanitize function.

To solve this: select the Entity ID on the Group Column menu and tick on the Group Columns (additional) Entity ID, Value and Format options.

AttachmentSizeStatusTest resultOperations
Screen shot 2012-07-20 at 11.00.07 AM.png33.91 KBIgnored: Check issue status.NoneNone

### #42

Thanks for #30 and #41 - this fix my problem!

### #43

Here's a fix that worked for me. You will need to turn on the "Always show the master display" option at /admin/structure/views/settings

I ran into this issue when I set Use aggregation to Yes in a view with multiple displays. I had applied aggregation to all displays, instead of just narrowing it down to only the one display.

Once I turned on aggregation, this error was appearing in every single display for the view. I went back into the view, turned off aggregation for all displays. I went into the fields, and made sure that these were different than the master display. In this case, I opened the title field and saved it with This page: override selected.

I then reactivated aggregation only on the display that needed it, making sure that the master display did not have aggregation activated. When done properly, the Aggregation settings link will appear in the display's field, but not in the master display.

I saved the display, and that did the trick.

### #44

I recommend to select "Entity ID" in the Group column of the Aggregation Settings of each of your fields.

Note: This can result in unexpected results but it's the only possible way to bypass the issue.

### #45

Tricky issue and it still in the latest versions of core & Views.

I figured out a solution which might not be ideal but helped me:

Add at line 266 & 320:

$item['format'] = isset($item['format']) ? \$item['format'] : 'full_html';

### #46

same here. solved by remove field from views and add it again

### #47

For me worked when I edit the "Strip HTML tags" checkbox on "REWRITE RESULTS" for the field.

### #48

@frizi (#45): Those lines you mentioned to add. To what file should they be added?

### #49

In my case I was trying to format th field as an URL using "Output this field as a link " in the Rewrite results section of the options. Selecting "Plain text" as formatter solves the issue for me. ¿Maybe the default selection of formatter is not loading correctly?

### #50

Adding the format and value to the aggregation setting for my body field as described in #35 worked for me.

### #51

When in views, editing a field, the option "Place a colon after the label". When it is unchecked, the error goes away for me.

### #52

Just in case someone else gets into the same trouble:
In my case this same problem happened when after a created a View I modified the content type of one of the fields (from text to node reference), then I started getting the message.
Solution:
In the View remove the modified field and add it again. After that the problem went away.
Greetings,
Eduardo

### #53

After i dig my head more and i got the solution.

Its mainly because of views misconfiguration. If you use Global: custom text and add the html code directly into the text box, you will get this error.

Solution:
Instead of using text box to add html code, use rewrite result and select Output this field as a link then add the link code and select strip html.

You will get rid of this issue.

### #54

@GaneshKumar Can you see if it's still happening when you set the filter to "Full HTML"? I'm not exactly sure if that's fixed it for me or not, but curious what it does for someone else... (For the Global: custom text box)

### #55

Yeah, this issue is NOT specific to views...

If you upgraded from D6 -> D7 and converted fields with option radio/buttons, you might run into this error.

The "Content Migrate" module may not do a very good job of updating the field in the database... I ended up having to manually update the database and fix the affected fields in the field_config_instance table.

### #56

WooHoo! Just figured out how to fix it! (Ok, for my use-case situation...) Been pulling my hair out the last two days trying to track down exactly what was going on since it wasn't directly a View related issue but I have a feeling my solution might be the cause of other's who ARE experiencing it on views...

As I mentioned before, I narrowed it down to my "Option Checkbox / Radio" fields. Looking into Devel, led me to look into the database. That led me to realize that the way the database was storing the field "Format", wasn't ever updated in the D6->D7 migration. D6 stored the format as "text_default" and D7 stores the format as "list_default" (For the radio buttons at least...)

If you aren't using a view on the page receiving the error, proceed below for my step by step solution. I recommend opening a second page that does show the errors, so you can test it again after doing the following steps. (In a nut shell, change the "Format" on the content display tab to "Key" then back to "Default" for every display that uses a list field.)

What I ended up having to do was:
1) Go to the default display of the content type. At the bottom you can choose to "Customize Display Settings" for the various displays (Teaser, RSS, Search Index etc.)
2) Enable each and every display. (Updating it in the default doesn't replicate to the rest :-/)
3) Start with the Default display and find ALL of your List(text) fields and change the format from "Default" to Key then save that display.
4) Next change them all from Key, back to Default. This will update the database to store it as the correct format.
5) Proceed with each of the remaining displays.
6) Test your page getting the errors.

If that doesn't fix it, you might load up Devel and see if you can figure anything else out... Hope that helps!

### #57

I had a similar problem, when the body field was added to fields list of a view, then the relationship was added, and the grouping turned on. After that in the preview section I saw that the content of the body field in preview data were not turned into html: i saw BR's there, etc.
I deleted the body field from the field list, and added it again. Is asked me whether i want to aggregate over it and i agreed. It asked if I wanted to add some more fields (subfields of body field?) and I included format field as well. The problem disappeared.

### #58

 Version: 7.x-3.x-dev » 7.x-3.7

Same issue with Drupal 7.19 / Views 7.x-3.7

solution #11 posted by e5sego worked for me...

#11
Changing the field formatter from default to plain text the notices disappeared.

Thanks.