Commit 8d526b10 authored by Dries's avatar Dries

- Patch #111719 by dvessel et al: ensure clean form IDs.

parent 3742d742
......@@ -2002,7 +2002,8 @@ function _form_set_class(&$element, $class = array()) {
}
/**
* Remove invalid characters from an HTML ID attribute string.
* Prepare an HTML ID attribute string by removing invalid characters and
* guaranteeing uniqueness.
*
* @param $id
* The ID to clean.
......@@ -2010,7 +2011,19 @@ function _form_set_class(&$element, $class = array()) {
* The cleaned ID.
*/
function form_clean_id($id = NULL) {
static $seen_ids = array();
$id = str_replace(array('][', '_', ' '), '-', $id);
// Ensure id's are unique. The first occurrence is held but left alone.
// Subsequent occurrences get a number appended to them.
if (isset($seen_ids[$id])) {
$id = $id .'-'. $seen_ids[$id]++;
}
else {
$seen_ids[$id] = 1;
}
return $id;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment