1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
<?php
namespace User\Form;
use Zend\InputFilter;
use Zend\Captcha;
use Zend\Form\Element;
use Zend\Form\Form;
class DiaporamaForm extends Form
{
private $_numFileElements = 1;
public function _($str)
{
return $str;
}
public function getMaxImages()
{
return $this->_numFileElements;
}
public function __construct($nbImagesMax = 1)
{
parent::__construct('diaporama');
$this->_numFileElements = $nbImagesMax;
$this->setAttribute('method', 'post');
$this->setAttribute('enctype', 'multipart/form-data');
$this->setAttribute('novalidate', 'novalidate');
$this->setAttribute('autocomplete', 'off');
$this->addElements();
$this->setInputFilter($this->createInputFilter());
}
public function addElements()
{
$this->add(array(
'name' => 'id',
'type' => 'Zend\Form\Element\Hidden',
'attributes' => array(),
'options' => array(
'label' => $this->_('Identifiant of the diaporama'),
//'column-size' => 'sm-10',
//'label_attributes' => array('class' => 'col-sm-2')
),
));
$this->add(array(
'name' => 'idUser',
'type' => 'Zend\Form\Element\Hidden',
'attributes' => array(
'required' => 'required',
),
'options' => array(
'label' => $this->_('Identification of user'),
//'column-size' => 'sm-10',
//'label_attributes' => array('class' => 'col-sm-2')
),
));
$this->add(array(
'name' => 'titreDiapo',
'type' => 'Zend\Form\Element\Text',
'attributes' => array(
'required' => 'required',
),
'options' => array(
'label' => $this->_('Name of the diaporama'),
//'column-size' => 'sm-10',
//'label_attributes' => array('class' => 'col-sm-2')
),
));
$this->add(array(
'name' => 'role',
'type' => 'Zend\Form\Element\Radio',
'attributes' => array(
'required' => 'required',
'value' => 'Public',
),
'options' => array(
'label' => $this->_('Status'),
'value_options' => array(
'Private' => $this->_('Private'),
'Public' => $this->_('Public'),
),
//'column-size' => 'sm-10',
//'label_attributes' => array('class' => 'col-sm-2')
),
));
// File Input
$file = new Element\File('file');
$file->setLabel($this->_('Titre of the imege'));
$file->setAttribute("class", "fielsetFile upload");
$file->setAttribute("required", false);
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'file-collection',
'attributes' => array(
'class' => "fielsetFile form-control"
),
'options' => array(
'label' => $this->_('New image'),
'help-block' => $this->_("We accept only the following formats: 'jpg', 'jpeg', 'png' and 'gif'"),
'count' => $this->_numFileElements,
'should_create_template' => true,
'allow_add' => true,
'allow_remove' => true,
'template_placeholder' => '__file-collection__',
'target_element' => $file
),
));
for( $i=0; $i < $this->_numFileElements; $i++ ) {
$this->add(array(
'name' => 'titre_'.$i,
'type' => 'Zend\Form\Element\Text',
'attributes' => array(
'id' => "titre_".$i,
'class' => "fielsetFile form-control"
),
'options' => array(
'label' => $this->_('Titre of the imege'),
//'column-size' => 'sm-10',
//'label_attributes' => array('class' => 'col-sm-2')
),
));
$this->add(array(
'name' => 'commentaire_'.$i,
'type' => 'Zend\Form\Element\Textarea',
'attributes' => array(
'id' => 'commentaire_'.$i,
'class' => "fielsetFile editor form-control"
),
'options' => array(
'label' => $this->_('Comment'),
//'column-size' => 'sm-10',
//'label_attributes' => array('class' => 'col-sm-2')
),
));
)
$this->add(array(
'name' => 'back',
'type' => 'button',
'attributes' => array('type' => 'submit'),
'options' => array(
'label' => $this->_('Back'),
'column-size' => 'sm-10 col-sm-offset-2'
)
));
$this->add(array(
'name' => 'submit',
'type' => 'button',
'attributes' => array('type' => 'submit', 'class' => 'btn-primary'),
'options' => array(
'label' => $this->_('Validate'),
'column-size' => 'sm-10 col-sm-offset-2'
)
));
}
public function createInputFilter()
{
$inputFilter = new InputFilter\InputFilter();
// ici le nombre de fichiers à uploader
//
// File Collection
$fileCollection = new InputFilter\InputFilter();
for ($i = 0; $i < $this->_numFileElements; $i++) {
$file = new InputFilter\FileInput($i);
//$file->setRequired(false);
$file->setRequired(true);
$file->getFilterChain()->attachByName(
'filerenameupload',
array(
'target' => './data/diaporamas/',
'overwrite' => true,
'use_upload_name' => true,
'randomize' => true
)
);
$fileCollection->add($file);
}
$inputFilter->add($fileCollection, 'file-collection');
// Text Input
$idUser = new InputFilter\Input('idUser');
$idUser->setRequired(true);
$inputFilter->add($idUser);
$titreDiapo = new InputFilter\Input('titreDiapo');
$titreDiapo->setRequired(true);
$inputFilter->add($titreDiapo);
return $inputFilter;
}
} |
Partager