request.php: submit an array with a html form
Opened this issue · 1 comments
domsie commented
If the HTML-Form POST value is an array if got an:
PHP Notice: Array to string conversion in /srv/www/htdocs/vendor/src/Http/Request.php on line 258
It´s within the following part of request.php:
// can be $_POST and $_FILES
public static function buildPostBody($fields, $files, $boundary = null)
{
...
foreach($fields as $name => $value){
$body .= sprintf($part_field, $boundary, $name, $value);
$body .= "{$value}\r\n";
}
One example could be:
<form action="" method="POST">
<input type="text" name="first_name">
<input type="text" name="last_name">
<input type="submit">
</form>
// Result of $_POST (PHP):
// array(
// 'first_name' => ''
// 'last_name' => ''
// )
domsie commented
In my view it could be solved with following part
foreach ($fields as $name => $value)
{
if ( is_array($value) )
{
foreach ( $value as $key => $val )
{
$body .= sprintf($part_field, $boundary, $key, $val);
$body .= "{$val}\r\n";
}
}
else
{
$body .= sprintf($part_field, $boundary, $name, $value);
$body .= "{$value}\r\n";
}
}