Skip to content

Commit 580be29

Browse files
authored
Merge pull request Athlon1600#113 from diffen/master
Bug fix for multi-value checkboxes in form data.
2 parents 0422e4d + 500638f commit 580be29

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Http/Request.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,16 @@ public static function buildPostBody($fields, $files, $boundary = null){
231231
$body = '';
232232

233233
foreach($fields as $name => $value){
234-
$body .= sprintf($part_field, $boundary, $name, $value);
235-
$body .= "{$value}\r\n";
234+
//checkboxes can have multiple values in an array.
235+
if(is_array($value)){
236+
foreach($value as $v){
237+
$body .= sprintf($part_field, $boundary, "{$name}[]", $v);
238+
$body .= "{$v}\r\n";
239+
}
240+
} else {
241+
$body .= sprintf($part_field, $boundary, $name, $value);
242+
$body .= "{$value}\r\n";
243+
}
236244
}
237245

238246
// data better have [name, tmp_name, and optional type]
@@ -359,4 +367,4 @@ public static function createFromGlobals(){
359367
}
360368

361369

362-
?>
370+
?>

0 commit comments

Comments
 (0)