Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
8d526b10
Commit
8d526b10
authored
Oct 19, 2007
by
Dries Buytaert
Browse files
- Patch
#111719
by dvessel et al: ensure clean form IDs.
parent
3742d742
Changes
1
Hide whitespace changes
Inline
Side-by-side
includes/form.inc
View file @
8d526b10
...
...
@@ -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
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment