I
I
ImPuuLsE2015-07-10 09:14:43
Yii
ImPuuLsE, 2015-07-10 09:14:43

Why doesn't CMultiFileUpload work in yii?

Hello! I can't figure out why $_Files is empty? and the View field itself is also not transferred to $_Post
:

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'npLoadScheme',
    'options'=>array(
        //'title'=>'Расчет по чертежу',
        'width'=>700,
        'height'=>400,
        'autoOpen'=>false,
        'resizable'=>false,
        'overlay'=>array(
            'backgroundColor'=>'#000',
            'opacity'=>'0.5'
        ),
    ),
));
$qForm = new NpSchemeForm();

$form = $this->beginWidget('CActiveForm', array(
    'id' => 'schemeNp-form',
    'enableAjaxValidation'=>true,
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
    ),
    'htmlOptions' => array(
        'enctype' => 'multipart/form-data')
));
?>
<div id="np-scheme-container">
    <span>Расчет по чертежу</span>

    <div class="np-scheme-errorMessage" id="np-scheme-formResult"></div>

    <?= $form->labelEx($qForm,'name'); ?>
    <?= $form->textField($qForm,'name', array('size'=>20)); ?>

    <?= $form->labelEx($qForm,'phone'); ?>
    <?= $form->textField($qForm,'phone', array('size'=>20)); ?>

    <?= $form->labelEx($qForm,'files'); ?>
    <?php
    $this->widget('CMultiFileUpload', array(
        'model'=>$qForm,
        'attribute'=>'files',
        'accept'=>'jpg|gif',
        'name'=>'NpSchemeFormImages'

    ));
    ?>
    <?= $form->labelEx($qForm,'comment'); ?>
    <?= $form->textField($qForm,'comment', array('size'=>20)); ?>

    <?= $form->labelEx($qForm,'email'); ?>
    <?= $form->textField($qForm,'email', array('size'=>20)); ?>
    <?= '<div class="helper">Для отслеживания состояния вашего заказа</div>'; ?>

    <?= CHtml::ajaxSubmitButton('Отправить заявку',array('/nptabs/ajax/SchemeNp'),array(
        'dataType'=>'json',
        'type'=>'post',
        
    ), array('class'=>'np_scheme_button', 'id'=>'schemeLoadFormButton'));?>
</div>
<?$this->endWidget();?>
<?$this->endWidget('zii.widgets.jui.CJuiDialog');?>

Model :
public $name;
    public $phone;
    public $comment;
    public $email;
    public $files;

    public function rules()
    {
        return array(
            array('name, phone', 'required'),
            array('phone', 'numerical'),
            array('comment, email, files', 'safe'),
        );
    }
  
    public function attributeLabels()
    {
        return array(
            'name'=>'Ваше имя',
            'phone'=>'Телефон',
            'comment'=>'Комментарий',
            'email'=>'Эл. почта',
            'files'=>'Файлы'
        );
    }

Controller:
if(isset($_POST['NpSchemeForm']))
        {
            $model->attributes=$_POST['NpSchemeForm'];
            $images = CUploadedFile::getInstancesByName('NpSchemeFormImages');
            CVarDumper::dump($images);die;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ImPuuLsE, 2015-07-10
@ImPuuLsE

as it turned out ajaxSubmitButton does not work with file uploads

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question