form_clean_id

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/form.inc, строка 2261

Версии
5
form_clean_id($id = NULL)
6
form_clean_id($id = NULL, $flush = FALSE)

Prepare an HTML ID attribute string for a form item.

Remove invalid characters and guarantee uniqueness.

Параметры

$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.

Возвращаемое значение

The cleaned ID.

Связанные темы

▾ 6 функции вызывают form_clean_id()

drupal_prepare_form in includes/form.inc
Подготавливает полный массив формы, добавляя в него недостающие значения по-умолчанию, вызывая нужные хуки, а также, опционально, выставляя токены валидации для некоторых полей, чтобы обезопасить форму от несанкционированных вмешательств.
drupal_process_form in includes/form.inc
Эта функция является основной в Forms API. Предназначена для построения формы и проверки формы на соответствие требованиям и обработки результатов.
expand_radios in includes/form.inc
Превращает элемент radios («список переключателей») в список еденичных элементов radio («переключатель»).
filter_form in modules/filter/filter.module
Generate a selector for choosing a format in a form. See alsofilter_form_validate()
template_preprocess_page in includes/theme.inc
Обрабатывает переменные для page.tpl.php
_form_builder_handle_input_element in includes/form.inc
Populate the #value and #name properties of input elements so they can be processed and rendered. Also, execute any #process handlers attached to a specific element.

Код

<?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;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему