Using hook_form_alter, I've added a 'text_format' element to the system theme settings form. Submitting the form, I get the following error:
Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1543 of /srv/www/vhosts/default/includes/bootstrap.inc).
It looks like the submit handler for the system_theme_settings form does not properly handle the new 'text_format' fapi element.
For reference, here is the form alter function (defined in theme-settings.php):
function mytheme_form_system_theme_settings_alter(&$form, &$form_state) {
$form['mytheme_settings']['frontpage_bigplay']['frontpage_body'] = array(
'#type' => 'text_format',
'#title' => t('Body'),
'#default_value' => theme_get_setting('frontpage_body','mytheme'),
'#format' => NULL,
);
}
Comments
Comment #1
AmiGator commentedGot same error
Comment #2
jisuo commentedSame error here too on 7.12
I had a form in my custom module:
Comment #3
manfredekblad commentedI'm getting the same error in bootstrap.inc, which I traced back to form.inc line 3769.
I think the variable $element is supposed to contain a key "#value" but it's missing the #... so it's just $element["value"], without the #. At least that's what I can see from doing a simple var_dump($element) inside the theme_textarea() function.
Update:
It does contain the key #value, just that it holds an array with the keys "value" and "format". check_plain() is expecting just a string, not an array, since it just pass that to htmlspecialchars().
Temporarily I fixed it by replacing theme_textarea() with this in includes/form.inc
Obviously that's just a quick n dirty fix.
Comment #4
jimmynash commentedI just ran into this using a text_format FAPI element on a custom modules system_settings_form.
Originally my form element was as such
Since I was getting back an array from the variable with both the value and the format, check_plain in theme_textarea was throwing the htmlspecialchars error.
I worked around it by getting the variable first and setting the parts to where they need to be in the form element array.
Hope this helps someone.
Comment #5
hillaevium commentedThanks jimmynash - that worked like a charm!
Comment #6
danny englanderOld issue here, but even with Drupal 7.27, I was still getting the Warning: htmlspecialchars() expects parameter 1 error. I can confirm that #4 above works great, exactly what I needed. This seems to be a work around though and not an actual fix.
Comment #7
PumaDias commentedThis helped for me:
bootstrap.inc -> line 1566
Comment #8
paulraj augustin commentedAfter working for an hour, I came up with the below solution to use text_format in theme-settings.php
Comment #9
hessam61 commented#8 worked for me. Thanks!
Comment #10
kenorb commentedWorkaround in case of custom field: If you changed #type from 'text' to 'text_format', you need to make sure your '#default_value' is also updated and it is a string, not an array.
Related: Field API field_schema for text field error