Skip to content

Commit 6f3b10f

Browse files
author
Vincent Chabot
committed
Add the sfWidgetFormInputFileMulti widget to allow multi upload file
1 parent 012a346 commit 6f3b10f

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

lib/autoload/sfCoreAutoload.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ static public function make()
517517
'sfwidgetforminput' => 'widget/sfWidgetFormInput.class.php',
518518
'sfwidgetforminputcheckbox' => 'widget/sfWidgetFormInputCheckbox.class.php',
519519
'sfwidgetforminputfile' => 'widget/sfWidgetFormInputFile.class.php',
520+
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
520521
'sfwidgetforminputfileeditable' => 'widget/sfWidgetFormInputFileEditable.class.php',
521522
'sfwidgetforminputhidden' => 'widget/sfWidgetFormInputHidden.class.php',
522523
'sfwidgetforminputpassword' => 'widget/sfWidgetFormInputPassword.class.php',

lib/widget/sfWidgetFormInputFile.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* This file is part of the symfony package.
55
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6-
*
6+
*
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/**
4+
* sfWidgetFormInputFileMulti represents an upload HTML input tag with multiple option.
5+
*
6+
* @package symfony
7+
* @subpackage widget
8+
* @author Vincent Chabot <vchabot@groupe-exp.com>
9+
* @version SVN: $Id$
10+
*/
11+
class sfWidgetFormInputFileMulti extends sfWidgetFormInputFile
12+
{
13+
/**
14+
* Configures the current widget.
15+
*
16+
* @param array $options An array of options
17+
* @param array $attributes An array of default HTML attributes
18+
*
19+
* @see sfWidgetFormInput
20+
*/
21+
protected function configure($options = array(), $attributes = array())
22+
{
23+
parent::configure($options, $attributes);
24+
25+
$this->addOption('multiple', true);
26+
}
27+
28+
/**
29+
* Renders the widget.
30+
*
31+
* @param string $name The element name
32+
* @param string $value The value displayed in this widget
33+
* @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
34+
* @param array $errors An array of errors for the field
35+
*
36+
* @return string An HTML tag string
37+
*
38+
* @see sfWidgetForm
39+
*/
40+
public function render($name, $value = null, $attributes = array(), $errors = array())
41+
{
42+
$name .= $this->getOption('multiple') ? '[]' : '';
43+
return $this->renderTag('input', array_merge(array('type' => $this->getOption('type'), 'name' => $name, 'value' => $value, 'multiple' => $this->getOption('multiple')), $attributes));
44+
}
45+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
require_once(__DIR__.'/../../bootstrap/unit.php');
4+
5+
$t = new lime_test(1);
6+
7+
$w = new sfWidgetFormInputFileMulti();
8+
9+
// ->render()
10+
$t->diag('->render() multiple file upload');
11+
$t->is($w->render('foo'), '<input type="file" name="foo[]" multiple="1" id="foo" />', '->render() renders the widget as HTML');
12+
13+

0 commit comments

Comments
 (0)