User login

Form altering certain CCK widget properties is tricky: adding and changing the size of an autocomplete textfield

This code (which is not called automatically but is a helper function for our hook_form_alter implementation) adds the suffix but does not change the forms size. Somehow these widget settings must get added later.

<?php
function biblioreference_alter_item(&$form, $key, $item, $fields) {
  $field_name = strstr($key, 'field_');
  if (isset($fields[$field_name]) && $fields[$field_name]['type'] == 'nodereference') {
    $type = $form['type']['#value'];
    $field = content_fields($field_name, $form['type']['#value']);
    if ($field['widget']['type'] == 'biblioreference_autocomplete') {
      // make the text field wider so the autocomplete looks better
      $form[$key][0]['#size'] = 100;
      // Add link to add new citation
      $suffix = '<div class="pdbiblio-add-new">';
      $suffix .= t('* If your reference is not in PD Biblio, <a href="@url" target="_BLANK">add a new citation in PDBiblio</a> manually.  This link will take you to a new window. After creating the reference, please remember to add it to the article.', array('@url' => url('biblioreference/add/citation')));
      $suffix .= '</div>';
      $form[$key]['#suffix'] = $suffix;
    }
  }
}
?>

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.