I have a content type where a field is the common name for a USA president. In examing a legacy database I'm importing some presidents have (simple) HTML in their name. For example Dwight Eisenhower <i>Ike</i>.

I would like to support this on a content type field field_people_common_name which is a textfield created in the Field UI.

Following these directions:

I've created a simple form alter hook to allow the input format of filtered_html on this form element:

function prez_people_form_people_node_form_alter(&$form, &$form_state, $form_id) {
  $form['field_people_common_name']['und'][0]['value']['#type'] = 'text_format';
  $form['field_people_common_name']['und'][0]['value']['#base_type'] = 'textfield';
  $form['field_people_common_name']['und'][0]['value']['#format'] = 'filtered_html';
  $form['field_people_common_name']['und'][0]['value']['#settings'] = array('text_processing ' => '1');

This appears to well, work or function:

enter image description here

But upon previewing the edit I get these errors:

Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen() (line 482 of ../htdocs/includes/unicode.inc).

Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1583 of ../htdocs/includes/bootstrap.inc).

Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1583 of ../htdocs/includes/bootstrap.inc).

Any idea how to get this to work. I'm trying to avoid embedding a text_area for simple textfield value (a name will never require a massive textarea .... yes I know I could make the textarea 1 row tall ....)

  • Is the field showing up in your preview? It sounds like something quirky with your install. I've had field configurations like this and I've never hit this error before.
    – Shawn Conn
    Apr 7, 2015 at 17:43
  • Yes it is but it's blank. It's not a problem with my installation. Maybe I have to alter the field widget instead ...
    – tenken
    Apr 7, 2015 at 18:52
  • Nevermind, I misread the problem. I thought you'd already performed the solution that Thomas4019 posted.
    – Shawn Conn
    Apr 7, 2015 at 19:06

1 Answer 1


You shouldn't need to use hook_form_alter to allow the user to specify an input format for a textfield. On the content type page, you can edit a fields settings and there is an option titled "Text Processing" that you will want to use instead.

enter image description here

Then when I look at my node form I see the following:

enter image description here

  • Sure, I'll buy this as an answer. For this project I'm migrating a large legacy DB into drupal -- re-configuring the field structure until it's right and re-importing everything... sounds like a PITA. But, after making the change I guess it's the only way to go as it appears to add a filter column to the DB schema.
    – tenken
    Apr 7, 2015 at 19:40
  • Yeah, the features module can help avoid some of that pain, but for just doing a migration it's overkill. The migrate module also might help, but it's pretty opinionated and has a learning curve.
    – Thomas4019
    Apr 7, 2015 at 21:12
  • I'm using both those modules :). I forgot a text field could have an input format -- I was hoping for a programmatic solution to altering the field to enable/store the filter type. It's a pain updating features and re-running migrations.
    – tenken
    Apr 7, 2015 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.