Помогите решить проблему. есть форма в модальном окне, которую нужно обработать и записать в бд. В форме есть поле для загрузки файла.
Помогите сделать правильный запрос.
модальное окно
Код: Выделить всё
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'agent-form',
'enableAjaxValidation'=>true,
'htmlOptions'=>array('enctype' => 'multipart/form-data'),
)); ?>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Новый контрагент</h5>
</div>
<div class="modal-body">
<?php
echo $form->textFieldRow($agent, 'name');
echo $form->textFieldRow($agent, 'reestr');
//echo $form->textFieldRow($agent, 'number');
echo $form->textFieldRow($agent, 'owner');
echo $form->textFieldRow($agent, 'city_reg');
echo $form->textFieldRow($agent, 'phone');
echo $form->textAreaRow($agent,'iur_address',array('rows'=>3, 'cols'=>10, 'class'=>'span3'));
echo $form->textAreaRow($agent,'fact_address',array('rows'=>3, 'cols'=>10, 'class'=>'span3'));
echo $form->labelEx($agent, 'contract_id');
echo $form->dropDownList($agent, 'contract_id', CHtml::ListData(Contract::model()->findAll(), 'id', 'name'), array('empty'=>'--Выбрать--'));
echo $form->labelEx($agent, 'document');
echo $form->fileField($agent, 'document');
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Закрыть</button>
<button type="submit" class="btn btn-success new-agent">Сохранить</button>
</div>
</div>
</div>
</div>
<?php $this->endWidget(); ?>
Код: Выделить всё
$('#agent-form').submit( function(event)
{
event.preventDefault();
var form = $(this)[0];
var data = new FormData(form);
$.ajax({
type:'post',
url: '/company/agent/newform',
data: data,
mimeType:"multipart/form-data",
cache: false,
contentType: false,
processData: false,
success: function(res)
{
console.log(res);
},
error:function()
{
console.log('no');
}
})
return false;
});