file upload - Yii form builder -



file upload - Yii form builder -

i've been working on yii-based application. , i've faced weird thing...

what i'm trying add together input(type=file) form. form created via form builder(cform class). input not going appear.

my code. controller/action:

$model=mymodel::model()->findbypk(700); $model->scenario='my-scenario'; $form=new cform('path.to.forms.my-form', $model); $this->render('view', array('form'=>$form));

view:

echo $form

form config:

return array( 'attributes' => array( 'enctype' => 'multipart/form-data', ), 'elements' => array( 'name' => array( 'type' => 'text', ), 'image' => array( 'type' => 'file', ), ), 'buttons' => array( 'save' => array( 'type' => 'submit', 'label' => 'save', ), ), );

model:

//..... public $image; // .... public function rules() { homecoming array( //... array('image', 'file', 'types'=>'png', 'on'=>'my-scenario'), ); }

with code above expected see 2 fields - text , file. text 1 appears.

if alter file validator to, say, required - works, need file validator.

i'm using yii version 1.1.13.

the intresting code above works expected before yii(1.1.9). known bug in new version? if yes - there solution? or have rollback previous version?

thanks in advance.

update:

if add together sec validator (one file , 1 required) work?

no, doesn't. believe found why. see bellow.

it seems caused line in cform..

yes, correct. yesterday, armed debugger went deeper:)

cformelement::getvisible() calls cmodel::isattributesafe() , cmodel::getsafeattributenames().

cform::getsafeattributenames() gets model validators , leaves safe ones. can see cfilevalidator not safe.

so, doesn't matter how many safe validators(required or other) have attribute assigned. cform::getsafeattributenames() removes whitelist if there @ to the lowest degree 1 unsafe(file). file validator unsafe since 1.1.12 version. why worked me in 1.1.9 :)

hence problem in cfilevalidator(or @ to the lowest degree connected it) , not in cform.

the 1 solution can see far creating own validator extended cfilevalidator marked safe , using instead of built in. can't imagine problems may cause(i believe yii developers had reason making unsafe).

i hope helpful somebody.

update 2

array('image', 'file', 'safe'=>true, 'types'=>'png', 'on'=>'my-scenario')

this validation rule(explicit safe=true) works.

if add together sec validator (one file , 1 required) work? ran myself.

it seems caused line in cform:

if($element->getvisible()) { ... }

the getvisible checks active validators current model scenario , leaves out inputs aren't used in current validator rules. i've ended commenting things out in our custom cform model our system, if allow me know if find works improve you.

file-upload yii formbuilder

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -