Community Documentation

Prefix / suffix

Last updated August 5, 2011. Created by Sutharsan on February 23, 2009.
Edited by Bojhan. Log in to edit this page.

Problem summary

  • the input text is part of a larger string (e.g. url, path) and description is used to explain what to enter and examples are given.
  • lack of context causes confusion of the required input in a text field.

Example

admin/settings/site-information front page: http://example.com/[ ]
$[ ].00
site/default/files/[ ]
http://example.com/[ ]/feed

Use when

  • text input fields used for path, file location, url, etc.
  • all possible input begins or ends with the same phrase.
  • text input fields where adding prefix and/or suffix clarifies the context.

Solution

Drupal's Form API (6.x and up) provides the ability to add prefix and suffix to text input fields using the #field_prefix and #field_suffix form contols. Prefix and suffix are placed inline with the text input field. Where the input is part of a larger string (e.g. url, file path, payment amount, etc.) prefix and/or suffix can be added to avoid confusion of the exact nature of the data to enter. This can reduce the amount of descriptive text or eliminate it at all.

Rationale

Recommendation

Where the prefix or suffix depends on system settings (e.g. base url) the prefix/suffix should be generated by php code to match the current situation the site is in.
Where prefix or suffix depends on other input on the same form javascript can be used to change the prefix/suffix content. Degradation should be taken care of.

Discussion

More examples

Page status

About this page

Drupal version
Drupal 6.x, Drupal 7.x

Archive

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here