开发者

File upload with Yii's ActiveForm

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 u开发者_JAVA技巧sing 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!


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')
));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜