I'm working in a module that allows users to add notes to images. I'm using the Form API reference to create the form field. In edit-mode the HTML works (links get rendered correctly, etc.), but when saved this code is converted to standard text.

This is what I used to create the form:

 * After build function to process the imagemaps widget on forms.
function imagemarker_process_form_element($element, $form_state) {

  // Leave alone if we are on the field ui settings.
  if (!isset($element['#field_name'])) {
    return $element;

  // Leave element when user doesn't have access.
  if (!user_access('add markers to images')) {
    return $element;

  $image_style = _imagemarker_get_fields_enabled_style($element['#entity_type'], $element['#field_name'], $element['#bundle']);

  // Leave element when no image style is found for current field.
  if (empty($image_style)) {
    return $element;

  $element['imagemarker'] = array(
    '#type' => 'markup',
    '#weight' => 10,
    '#suffix' => '',

  if ($element['fid']['#value']) {
    $element['imagemarker']['#prefix'] = '';
    $element['imagemarker']['#markup'] = imagemarker_widget($element);
    $form['#submit'][] = 'imagemarker_widget_submit';
  else {
    $element['imagemarker']['#prefix'] = '';
    $element['imagemarker']['#markup'] = t('Once an image is uploaded you will be able to add up to 3 markers to it.');

  return $element;

 * Create a widget to create and manage imagemarker.
 * @param $element
 *   Form element of the image.
function imagemarker_widget(&$element) {

  $settings = field_read_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
  $image_style = $settings['settings']['imagemarker_style'];
  $langcode = $element['#language'];
  $output = '';

  if (isset($element['#default_value'], $element['#default_value']['uri'])) {
    $coordinates = _imagemarker_get_coordinates($element['#default_value']['fid']);
    $output .= _imagemarker_render($element['#default_value']['uri'], $coordinates, $image_style);
    $properties = _imagemarker_load_imagestyle($image_style);
    $output .= '';

    // Attach the javascript and css files for the imagemap UI.
    $element['#attached'] = array(
      'js' => array(
        drupal_get_path('module', 'imagemarker') . '/imagemarker.js',
        drupal_get_path('module', 'imagemarker') . '/imagemarker.admin.js'
      'css' => array(
        drupal_get_path('module', 'imagemarker') . '/imagemarker.css'

  return $output;


What am I missing? Does this have to do with the Text format permissions or is this something I can fixed in the code?

  • where are you tying to save? – Mohammed Shameem Jan 23 '13 at 4:21
  • Each annotation is saved to the database. When I paste Html code before saving it, it gets rendered correctly. But after I save it the Html code becomes plain text. I want to be able to embed media in the annotations. – anthony Jan 24 '13 at 1:05
  • is it saved to a field of the content type? if yes then you should set the format of the field to Full HTML – Mohammed Shameem Jan 24 '13 at 3:33
  • No, its not saved as a field of the content type. That's the main issue. Because of that the HTML format settings does not apply to the annotations. – anthony Jan 24 '13 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.