File upload with Yii's ActiveForm

半城伤御伤魂 提交于 2019-12-24 09:27:24

问题


I am trying to use Yii's ActiveForm to create a basic registration page with an image upload field. However, I am running into problems. I am using the following code to create the form tags:

$form=$this->beginWidget('CActiveForm', array(
                                'id'=>'activity_form', 
                                'enableAjaxValidation'=>true, 
                                'stateful'=>true, 
                                'enctype'=>'multipart/form-data'
                                ));

The above code produces the following error message in Yii:

Property "CActiveForm.enctype" is not defined

I've also tried:

$form=$this->beginWidget('CActiveForm', array(
                                'id'=>'activity_form', 
                                'enableAjaxValidation'=>true, 
                                'stateful'=>true, 
                                array('enctype'=>'multipart/form-data')));

as well as:

$form=$this->beginWidget('CActiveForm', array(
                                'id'=>'activity_form', 
                                'enableAjaxValidation'=>true, 
                                'stateful'=>true), 
                                array('enctype'=>'multipart/form-data')));

But neither of these work.

Any ideas as to what could be wrong? Can I use beginWidget to create a multipart form with file upload capabilities? What's the format I should follow for this? I can't seem to find any answers in the documentation or the forums.

Thanks!


回答1:


Never mind. I found the solution to this. The trick is to use htmlOptions like so:

$this->beginWidget('CActiveForm', array(
  'id'=>'activity_form', 
  'enableAjaxValidation'=>true, 
  'stateful'=>true, 
  'htmlOptions'=>array('enctype' => 'multipart/form-data')
));


来源:https://stackoverflow.com/questions/3607200/file-upload-with-yiis-activeform

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!