Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
a7bced32
Commit
a7bced32
authored
19 years ago
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Patch
#18663
by chx: fix empty form elements.
parent
a31b1b38
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/common.inc
+36
-9
36 additions, 9 deletions
includes/common.inc
index.php
+1
-0
1 addition, 0 deletions
index.php
with
37 additions
and
9 deletions
includes/common.inc
+
36
−
9
View file @
a7bced32
...
...
@@ -429,6 +429,38 @@ function fix_gpc_magic() {
}
}
/**
* An unchecked checkbox is not present in $_POST so we fix it here by
* proving a default value of 0. Also, with form_checkboxes() we expect
* an array, but HTML does not send the empty array. This is also taken
* care off.
*/
function
fix_checkboxes
()
{
if
(
isset
(
$_POST
[
'form_array'
]))
{
$_POST
[
'edit'
]
=
_fix_checkboxes
(
$_POST
[
'edit'
],
$_POST
[
'form_array'
],
array
());
}
if
(
isset
(
$_POST
[
'form_zero'
]))
{
$_POST
[
'edit'
]
=
_fix_checkboxes
(
$_POST
[
'edit'
],
$_POST
[
'form_zero'
],
0
);
}
}
function
_fix_checkboxes
(
$array1
,
$array2
,
$value
)
{
if
(
is_array
(
$array2
)
&&
count
(
$array2
))
{
foreach
(
$array2
as
$k
=>
$v
)
{
if
(
is_array
(
$v
)
&&
count
(
$v
))
{
$array1
[
$k
]
=
_fix_checkboxes
(
$array1
[
$k
],
$v
,
$value
);
}
else
if
(
!
isset
(
$array1
[
$k
]))
{
$array1
[
$k
]
=
$value
;
}
}
}
else
{
$array1
=
$value
;
}
return
$array1
;
}
/**
* @name Conversion
* @{
...
...
@@ -1160,9 +1192,7 @@ function form_checkbox($title, $name, $value = 1, $checked = FALSE, $description
if
(
!
is_null
(
$title
))
{
$element
=
'<label class="option">'
.
$element
.
' '
.
$title
.
'</label>'
;
}
// Note: because unchecked boxes are not included in the POST data, we include
// a form_hidden() which will be overwritten for a checked box.
return
form_hidden
(
$name
,
0
)
.
theme
(
'form_element'
,
NULL
,
$element
,
$description
,
$name
,
$required
,
_form_get_error
(
$name
));
return
form_hidden
(
$name
,
1
,
'form_zero'
)
.
theme
(
'form_element'
,
NULL
,
$element
,
$description
,
$name
,
$required
,
_form_get_error
(
$name
));
}
/**
...
...
@@ -1195,10 +1225,7 @@ function form_checkboxes($title, $name, $values, $options, $description = NULL,
foreach
(
$options
as
$key
=>
$choice
)
{
$choices
.
=
'<label class="option"><input type="checkbox" class="form-checkbox" name="edit['
.
$name
.
'][]" value="'
.
$key
.
'"'
.
(
in_array
(
$key
,
$values
)
?
' checked="checked"'
:
''
)
.
drupal_attributes
(
$attributes
)
.
' /> '
.
$choice
.
'</label><br />'
;
}
// Note: because unchecked boxes are not included in the POST data, we
// include a form_hidden() which will be overwritten as soon as there is at
// least one checked box.
return
form_hidden
(
$name
,
0
)
.
theme
(
'form_element'
,
$title
,
$choices
,
$description
,
NULL
,
$required
,
_form_get_error
(
$name
));
return
form_hidden
(
$name
,
1
,
'form_array'
)
.
theme
(
'form_element'
,
$title
,
$choices
,
$description
,
NULL
,
$required
,
_form_get_error
(
$name
));
}
}
...
...
@@ -1376,8 +1403,8 @@ function form_file($title, $name, $size, $description = NULL, $required = FALSE)
* but be sure to validate the data on the receiving page as it is possible for
* an attacker to change the value before it is submitted.
*/
function
form_hidden
(
$name
,
$value
)
{
return
'<input type="hidden" name="edit['
.
$name
.
']" value="'
.
check_plain
(
$value
)
.
"
\"
/>
\n
"
;
function
form_hidden
(
$name
,
$value
,
$edit
=
'edit'
)
{
return
'<input type="hidden" name="
'
.
$
edit
.
'
['
.
$name
.
']" value="'
.
check_plain
(
$value
)
.
"
\"
/>
\n
"
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
index.php
+
1
−
0
View file @
a7bced32
...
...
@@ -14,6 +14,7 @@
include_once
'includes/common.inc'
;
fix_gpc_magic
();
fix_checkboxes
();
$return
=
menu_execute_active_handler
();
switch
(
$return
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment