문제

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!

도움이 되었습니까?

해결책

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')
));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top