4.7.x form.inc theme_textfield($element)
5.x form.inc theme_textfield($element)
6.x form.inc theme_textfield($element)
7.x form.inc theme_textfield($variables)

Returns HTML for a textfield form element.

Parameters

$variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #title, #value, #description, #size, #maxlength, #required, #attributes, #autocomplete_path.

Related topics

1 theme call to theme_textfield()
system_element_info in modules/system/system.module
Implements hook_element_info().

File

includes/form.inc, line 4011
Functions for form and batch generation and processing.

Code

function theme_textfield($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'text';
  element_set_attributes($element, array(
    'id',
    'name',
    'value',
    'size',
    'maxlength',
  ));
  _form_set_class($element, array(
    'form-text',
  ));
  $extra = '';
  if ($element['#autocomplete_path'] && !empty($element['#autocomplete_input'])) {
    drupal_add_library('system', 'drupal.autocomplete');
    $element['#attributes']['class'][] = 'form-autocomplete';
    $attributes = array();
    $attributes['type'] = 'hidden';
    $attributes['id'] = $element['#autocomplete_input']['#id'];
    $attributes['value'] = $element['#autocomplete_input']['#url_value'];
    $attributes['disabled'] = 'disabled';
    $attributes['class'][] = 'autocomplete';
    $extra = '<input' . drupal_attributes($attributes) . ' />';
  }
  $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
  return $output . $extra;
}

Comments

drastik’s picture

  • #title isn't used.
  • #description isn't used.
  • #name is required to set name attribute on the input element (kind of important).
  • #autocomplete_path is required even if just set to FALSE to prevent Undefined index warnings.
bribread22’s picture

Below is an example implementation of theme_textfield:

print theme('textfield', array('element' => array('#attributes' => array('class' => array('my-textfield-class')))));