form_clean_id

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 form_clean_id($id = NULL, $flush = FALSE)

Prepare an HTML ID attribute string for a form item.

Remove invalid characters and guarantee uniqueness.

Übergabeparameter

$id The ID to clean.

$flush If set to TRUE, the function will flush and reset the static array which is built to test the uniqueness of element IDs. This is only used if a form has completed the validation process. This parameter should never be set to TRUE if this function is being called to assign an ID to the #ID element.

Rückgabewert

The cleaned ID.

Verwandte Themen

▾ 10 functions call form_clean_id()

drupal_prepare_form in includes/form.inc
Prepares a structured form array by adding required elements, executing any hook_form_alter functions, and optionally inserting a validation token to prevent tampering.
drupal_process_form in includes/form.inc
This function is the heart of form API. The form gets built, validated and in appropriate cases, submitted.
field_add_more_js in modules/field/field.form.inc
Menu callback for AHAH addition of new empty widgets.
filter_form in modules/filter/filter.module
Generate a selector for choosing a format in a form.
form_builder in includes/form.inc
Walk through the structured form array, adding any required properties to each element and mapping the incoming $_POST data to the proper elements. Also, execute any #process handlers attached to a specific element.
form_process_radios in includes/form.inc
Roll out a single radios element to a list of radios, using the options array as index.
form_process_tableselect in includes/form.inc
Create the correct amount of checkbox or radio elements to populate the table.
form_test_test_form in modules/simpletest/tests/form_test.module
A simple form to test clean_id generation.
ProfileTestAutocomplete::testAutocomplete in modules/profile/profile.test
Tests profile field autocompletion and access.
template_preprocess_page in includes/theme.inc
Process variables for page.tpl.php

Code

includes/form.inc, line 2670

<?php
function form_clean_id($id = NULL, $flush = FALSE) {
  static $seen_ids = array();

  if ($flush) {
    $seen_ids = array();
    return;
  }
  $id = str_replace(array('][', '_', ' '), '-', $id);

  // Ensure IDs are unique. The first occurrence is held but left alone.
  // Subsequent occurrences get a number appended to them. This incrementing
  // will almost certainly break code that relies on explicit HTML IDs in
  // forms that appear more than once on the page, but the alternative is
  // outputting duplicate IDs, which would break JS code and XHTML
  // validity anyways. For now, it's an acceptable stopgap solution.
  if (isset($seen_ids[$id])) {
    $id = $id . '-' . $seen_ids[$id]++;
  }
  else {
    $seen_ids[$id] = 1;
  }

  return $id;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen